Basic framework for main backup script

This commit is contained in:
Eric Torres 2019-03-13 02:19:20 -07:00
parent dde0609f3d
commit 5625987241
2 changed files with 70 additions and 0 deletions

View File

@ -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

View File

@ -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)