From 5625987241392e385cb0f980497ad7664a6bfb44 Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Wed, 13 Mar 2019 02:19:20 -0700 Subject: [PATCH] Basic framework for main backup script --- README.rst | 22 ++++++++++++++++++++++ bin/backup | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/README.rst b/README.rst index e69de29..8a02a8a 100644 --- a/README.rst +++ b/README.rst @@ -0,0 +1,22 @@ +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/ambv/black + +rbackup - An rsync-based backup tool +==================================== + +Features +-------- +* Snapshot-based backup management +* Backups of deleted and modified files + +Implementation Notes +-------------------- +* os.path is used for path-handling +* Use --link-dest= +* Use --suffix=, --backup, and --backup-dir= + +To-Do +----- +* rsync reads paths with a ':' as a remote host, do not do that + +rsync --archive --prune-dirs --hard-links --verbose --link-dest='current_snapshot_dir' --recursive --ignore-missing-args --files-from /etc /backup_dir/etc diff --git a/bin/backup b/bin/backup index a93a4bf..8d894fa 100644 --- a/bin/backup +++ b/bin/backup @@ -1 +1,49 @@ #!/usr/bin/python3 +""" +Run a backup. + +Command-Line Arguments +====================== +""" +import argparse +import logging +import os.path +import rbackup.rsync as rsync + +from rbackup.hierarchy import Hierarchy + +# ========== Constants ========== +RSYNC_DEFAULT_OPTS = [ + "--archive", + "--hard-links", + "--prune-dirs", + "--backup", + "--ignore-missing-args", +] +EXTRA_RSYNC_OPTS = {"dry_run": "--dry-run"} + +# ========== Logging Setup ========== + +# ========== Main Script ========== +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "-d", + "--dry-run", + action="append_const", + dest="extra_rsync_opts", + const=EXTRA_RSYNC_OPTS["dry_run"], + help="pass --dry-run to rsync", + ) + parser.add_argument("dest", help="destination directory", metavar="destination") + + args = parser.parser_args() + + hier = Hierarchy(args.dest) + link_dest = hier.prev_snapshot + + # Backup to hier.curr_snapshot + + # Relink 'prev' to point to current snapshot + os.remove(hier.prev_snapshot_link) + os.symlink(curr_snapshot, hier.prev_snapshot_link, target_is_directory=True)