summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile19
-rw-r--r--src/debug.py18
-rw-r--r--src/scripts/xbackup21
-rw-r--r--src/setup.py23
-rw-r--r--src/xbackup/__init__.py0
-rw-r--r--src/xbackup/backup.py98
-rw-r--r--src/xbackup/config.py25
-rw-r--r--src/xbackup/prune.py49
-rw-r--r--src/xbackup/script.py94
-rw-r--r--src/xbackup/utils.py36
11 files changed, 0 insertions, 384 deletions
diff --git a/src/.gitignore b/src/.gitignore
deleted file mode 100644
index 378eac2..0000000
--- a/src/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-build
diff --git a/src/Makefile b/src/Makefile
deleted file mode 100644
index 5401e84..0000000
--- a/src/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-# vim: shiftwidth=4 softtabstop=4 tabstop=4 noexpandtab
-
-
-DESTDIR="" # leave empty for the current system or provide a fakeroot here
-
-
-.PHONY: all clean install
-
-
-all:
- python3 setup.py build
-
-
-clean:
- rm -rf build
-
-
-install: all
- python3 setup.py install --root=$(DESTDIR) --optimize=1 --skip-build
diff --git a/src/debug.py b/src/debug.py
deleted file mode 100644
index 1deaf45..0000000
--- a/src/debug.py
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/python3
-# vim: shiftwidth=4 softtabstop=4 tabstop=4 expandtab
-
-
-"""A Debug Script for Development Purposes"""
-
-
-from xbackup import script
-
-
-def main():
- """main function of this script"""
-
- script.run()
-
-
-if __name__ == "__main__":
- main()
diff --git a/src/scripts/xbackup b/src/scripts/xbackup
deleted file mode 100644
index 569202e..0000000
--- a/src/scripts/xbackup
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/python3
-# vim: shiftwidth=4 tabstop=4 expandtab
-
-
-"""Main Executable of xbackup
-
-Have a look at https://cgit.xengineering.eu/xbackup for details.
-"""
-
-
-from xbackup import script
-
-
-def main():
- """Main Function of this Script"""
-
- script.run()
-
-
-if __name__ == "__main__":
- main()
diff --git a/src/setup.py b/src/setup.py
deleted file mode 100644
index 0ba6d7a..0000000
--- a/src/setup.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/python3
-# vim: shiftwidth=4 softtabstop=4 tabstop=4 expandtab
-
-
-"""setup.py
-
-Configuration file for setuptools.
-"""
-
-
-from distutils.core import setup
-
-
-setup(
- name="xbackup",
- version="1.0.0",
- description="Convenience wrapper around the Borg backup tool",
- author="xengineering",
- author_email="me@xengineering.eu",
- url="https://xengineering.eu",
- packages=["xbackup"],
- scripts=["scripts/xbackup"],
-)
diff --git a/src/xbackup/__init__.py b/src/xbackup/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/src/xbackup/__init__.py
+++ /dev/null
diff --git a/src/xbackup/backup.py b/src/xbackup/backup.py
deleted file mode 100644
index 8378977..0000000
--- a/src/xbackup/backup.py
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/python3
-# vim: shiftwidth=4 softtabstop=4 tabstop=4 expandtab
-# pylint: disable=too-few-public-methods
-
-
-"""backup.py
-
-This module contains the backup functionality of xbackup.
-"""
-
-
-import os
-
-from xbackup.utils import POSITIVE_ANSWERS,shell
-
-
-def backup(generic_cfg, paths_cfg, scripted):
- """perform a file-based full system backup"""
-
- # generate all necessary paths based on config
- paths = Filepaths(generic_cfg, paths_cfg)
- print(paths)
-
- # get confirmation from user if not in scripted execution mode
- if not scripted:
- answer = input("\nDo you want to continue? [y/N] ")
- if answer not in POSITIVE_ANSWERS:
- print("\nTerminated.")
- return
-
- # init borg repository (accepting failure on already existing repo)
- shell(f"borg init -e none {paths.borg_repo}", panic=False)
-
- # run backup
- run_backup(paths)
-
-
-class Filepaths():
- """A Container Class to hold Filepaths for the Borg Backup Tool"""
-
- def __init__(self, generic_cfg, paths_cfg):
- """The Constructor"""
-
- # parse backup source (usually / for system backups)
- self.backup_root = paths_cfg["backup_root"]
-
- # parse folder for borg repositories
- self.borg_repos_folder = generic_cfg["borg_repos_folder"]
-
- # path to the borg repository
- hostname = os.uname()[1]
- self.borg_repo = os.path.join(self.borg_repos_folder, hostname)
-
- # create blacklist of folders to be excluded from the backup
- self.blacklist = []
- for entry in paths_cfg["blacklist"]:
- self.blacklist.append(os.path.join(self.backup_root, entry))
-
- # avoid matroska-style backups of backups (yes, it is important)
- self.blacklist.append(self.borg_repos_folder)
-
- def __str__(self):
- """Converts an Object based on this Class to a String"""
-
- retval = ""
-
- retval += "\nbackup_root:\n" + self.backup_root + "\n"
-
- retval += "\nblacklist:\n"
- for item in self.blacklist:
- retval += item + "\n"
-
- retval += "\nborg_repo:\n" + self.borg_repo
-
- return retval
-
-
-def run_backup(paths):
- """Execute the Borg Backup"""
-
- # base command
- command = "borg create -v --stats --compression zstd \\"
-
- # set repository path
- command += \
- f"{paths.borg_repo}::'{{hostname}}-{{user}}-{{now:%Y-%m-%d_%H:%M:%S}}' \\"
-
- # set backup source
- command += f"\n {paths.backup_root} \\"
-
- # append blacklist elements
- for key,value in enumerate(paths.blacklist):
- command += f"\n --exclude '{value}'"
- if key != len(paths.blacklist) -1:
- command += " \\"
-
- # run command
- shell(command)
diff --git a/src/xbackup/config.py b/src/xbackup/config.py
deleted file mode 100644
index 4c72915..0000000
--- a/src/xbackup/config.py
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/python3
-# vim: shiftwidth=4 softtabstop=4 tabstop=4 expandtab
-
-
-"""Module for Configuration Parsing Functionality of xbackup"""
-
-
-import json
-
-
-def get(path):
- """read and parse the xbackup configuration file"""
-
- with open(path, "r", encoding="utf-8") as _file:
- content = _file.read()
-
- return json.loads(content)
-
-def dump(config, pretty=True):
- """returns the given configuration as JSON string"""
-
- if pretty:
- return json.dumps(config, indent=4)
-
- return json.dumps(config)
diff --git a/src/xbackup/prune.py b/src/xbackup/prune.py
deleted file mode 100644
index 7e57830..0000000
--- a/src/xbackup/prune.py
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/bin/python3
-# vim: shiftwidth=4 softtabstop=4 tabstop=4 expandtab
-
-
-"""prune.py
-
-This module contains the pruning functionality of xbackup.
-"""
-
-
-import os
-
-from xbackup.utils import POSITIVE_ANSWERS,shell
-
-
-def prune(generic_cfg, prune_cfg, scripted):
- """prune backups"""
-
- # generate backup repository path
- hostname = os.uname()[1]
- repo = os.path.join(generic_cfg["borg_repos_folder"], hostname)
-
- # parse prune values
- hourly = prune_cfg["keep-hourly"]
- daily = prune_cfg["keep-daily"]
- weekly = prune_cfg["keep-weekly"]
- monthly = prune_cfg["keep-monthly"]
- yearly = prune_cfg["keep-yearly"]
-
- # generate command
- cmd = f"borg prune -v {repo}"
- cmd += f" -H {hourly} -d {daily} -w {weekly} -m {monthly} -y {yearly}"
-
- # ask if execution is wanted
- if not scripted:
- text = f"\nGoing to prune your backups at '{repo}'."
- text += "\nThis will delete every backup except:"
- text += f"\n- {hourly} hourly backups"
- text += f"\n- {daily} daily backups"
- text += f"\n- {weekly} weekly backups"
- text += f"\n- {monthly} monthly backups"
- text += f"\n- {yearly} yearly backups"
- text += "\nDo you want to continue? [y/N] "
- answer = input(text)
- if answer not in POSITIVE_ANSWERS:
- return
-
- # execute pruning
- shell(cmd, panic=True)
diff --git a/src/xbackup/script.py b/src/xbackup/script.py
deleted file mode 100644
index 9d80603..0000000
--- a/src/xbackup/script.py
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/usr/bin/python3
-# vim: shiftwidth=4 softtabstop=4 tabstop=4 expandtab
-
-
-"""Module for the Script Functionality of xbackup"""
-
-
-import argparse
-import sys
-
-from xbackup import config
-from xbackup import backup
-from xbackup import prune
-
-
-def run():
- """runs xbackup script functionality"""
-
- args = parse_arguments()
- cfg = config.get(args.config)
-
- welcome()
-
- if args.command == "backup":
- backup.backup(cfg["generic"], cfg["paths"], args.scripted)
- elif args.command == "prune":
- prune.prune(cfg["generic"], cfg["prune"], args.scripted)
- else:
- print(f"Unknown command '{args.command}'")
- sys.exit(1)
-
- bye()
-
-def parse_arguments():
- """handles argument parsing with the argparse module"""
-
- # parser creation
- parser = argparse.ArgumentParser(
- prog="xbackup",
- description= \
- "xbackup CLI Script to make a File-based full System Backup",
- epilog= \
- "Project page: https://cgit.xengineering.eu/xbackup",
- )
-
- # main command argument (positional)
- parser.add_argument("command", type=str,
- help="the action to be performed",
- choices=["backup", "prune"]
- )
-
- # path to configuration file (optional)
- parser.add_argument("-c", "--config", type=str,
- metavar="CONFIG",
- help="path to the JSON configuration file",
- default="/etc/xbackup/config.json",
- )
-
- # flag for scripted execution (optional)
- parser.add_argument("-s", "--script",
- dest="scripted",
- action="store_true",
- help="use this flag to enable a non-interactive mode"
- )
- parser.set_defaults(scripted=False)
-
- # argument parsing
- args = parser.parse_args()
- return args
-
-
-def welcome():
- """Print Welcome Text"""
-
- print(r"""
-################################################################################
- _ _
- __ _| |__ __ _ ___| | ___ _ _ __
- \ \/ / '_ \ / _` |/ __| |/ / | | | '_ \
- > <| |_) | (_| | (__| <| |_| | |_) |
- /_/\_\_.__/ \__,_|\___|_|\_\\__,_| .__/
- |_|
-
-################################################################################
-""", end="")
-
-
-def bye():
- """Print final Text"""
-
- print("""
-################################################################################
-
-""", end="")
diff --git a/src/xbackup/utils.py b/src/xbackup/utils.py
deleted file mode 100644
index e1480d1..0000000
--- a/src/xbackup/utils.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/python3
-# vim: shiftwidth=4 softtabstop=4 tabstop=4 expandtab
-
-
-"""utils.py
-
-This module contains reusable code for xbackup.
-"""
-
-
-import sys
-import subprocess
-
-
-POSITIVE_ANSWERS = ["Y", "y", "Yes", "yes", "YES"]
-
-
-def shell(command, panic=True):
- """Savely execute a Shell Command
-
- - set panic=False to continue with execution on non-zero return code
- """
-
- # print command
- print("\nExecuting '" + command + "' ...")
-
- # command execution
- return_code = subprocess.call(command, shell=True)
-
- # handle non-zero return code
- if return_code != 0 and panic:
- print(f"Command '{command}'\nfailed with return code {return_code}")
- sys.exit(return_code)
-
- # final message and return
- print("... done!")