Add modules for basic functions
This commit is contained in:
parent
a3717ce355
commit
afa4eb9975
0
rbackup/__init__.py
Normal file
0
rbackup/__init__.py
Normal file
12
rbackup/date.py
Normal file
12
rbackup/date.py
Normal file
@ -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())
|
56
rbackup/hierarchy.py
Normal file
56
rbackup/hierarchy.py
Normal file
@ -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
|
17
rbackup/rsync.py
Normal file
17
rbackup/rsync.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user