49 lines
1.5 KiB
Python
Executable File
49 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
import re
|
|
|
|
from b2mirror import mirror
|
|
import logging
|
|
|
|
|
|
def main():
|
|
logging.basicConfig(level=logging.DEBUG,
|
|
format="%(asctime)-15s %(levelname)-8s %(filename)s:%(lineno)d %(message)s")
|
|
logging.getLogger("requests").setLevel(logging.ERROR)
|
|
logging.getLogger("urllib3").setLevel(logging.ERROR)
|
|
|
|
log = logging.getLogger("main")
|
|
|
|
parser = argparse.ArgumentParser(description="Sync data to/from B2")
|
|
|
|
parser.add_argument("-i", "--size", help="Compare by size instead of mtime", action="store_true", default=False)
|
|
parser.add_argument("-w", "--workers", help="Maximum parallel uploads", type=int, default=10)
|
|
|
|
parser.add_argument("-s", "--source", required=True, help="Source URI")
|
|
parser.add_argument("-d", "--dest", required=True, help="Dest URI")
|
|
|
|
parser.add_argument("-a", "--account-id", required=True, help="Backblaze account ID")
|
|
parser.add_argument("-k", "--app-key", required=True, help="Backblaze application key")
|
|
|
|
parser.add_argument("--exclude", nargs="+", help="List of regexes to exclude from transfer")
|
|
|
|
args = parser.parse_args()
|
|
|
|
ignore_res = [re.compile(i) for i in args.exclude] if args.exclude else []
|
|
|
|
log.debug("Running with params: %s", args)
|
|
|
|
mirror.sync(
|
|
args.source,
|
|
args.dest,
|
|
args.account_id,
|
|
args.app_key,
|
|
workers=args.workers,
|
|
exclude=ignore_res,
|
|
compare_method="size" if args.size else "mtime"
|
|
)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|