diff --git a/rbackup/__init__.py b/rbackup/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rbackup/date.py b/rbackup/date.py new file mode 100644 index 0000000..bb7963b --- /dev/null +++ b/rbackup/date.py @@ -0,0 +1,12 @@ +import datetime +import os.path + +def gen_datetime(*paths): + """Generate a path for a backup directory that contains + the current date and time. + + :param paths: paths to prepend to the result + :type paths: str, bytes, or path-like object + :returns: stuff + """ + return os.path.join(*paths, datetime.datetime.utcnow().isoformat()) diff --git a/rbackup/hierarchy.py b/rbackup/hierarchy.py new file mode 100644 index 0000000..8144b2f --- /dev/null +++ b/rbackup/hierarchy.py @@ -0,0 +1,56 @@ +"""This module contains a class for creating a backup hierarchy.""" +import os.path + +class Hierarchy(): + dest = None + + def Hierarchy(self, dest): + """Default constructor for the hierarchy class. + + :param dest: the root directory of the backup hierarchy + :type dest: str, bytes, or path-like object + """ + if not os.path.isdir(dest): + raise ValueError(f"{dest} is not a valid directory") + + self.dest = dest + + @property + def etc_dir: + """Retrieve the /etc backup directory of this hierarchy. + + :rtype: str + """ + return os.path.join(self.dest, backup, etc) + + @property + def home_dir: + """Retrieve the /home backup directory of this hierarchy. + + :rtype: str + """ + return os.path.join(self.dest, backup, home) + + @property + def snapshot_dir: + """Retrieve the snapshot directory of this hierarchy. + + :rtype: str + """ + return os.path.join(self.dest, backup, snapshots) + + @property + def root_home_dir: + """Retrieve root's home directory of this hierarchy. + + :rtype: str + """ + return os.path.join(self.dest, backup, root) + + @property + def base_dir: + """Return the base directory of this hierarchy. + + :rtype: str + """ + return dest diff --git a/rbackup/rsync.py b/rbackup/rsync.py new file mode 100644 index 0000000..f5eed3c --- /dev/null +++ b/rbackup/rsync.py @@ -0,0 +1,17 @@ +import subprocess + + +# ========== Constants ========== +_RSYNC_BIN = '/usr/bin/rsync' + + +# ========== Functions ========== +def rsync(*args): + """Run an rsync command. + + :param args: all arguments to pass to rsync + :type args: str + :raises: subprocess.CalledProcessError if rsync process failed + """ + cmd = [_RSYNC_BIN, *args] + subprocess.run(cmd, capture_output=True, check=True)