diff --git a/.gitignore b/.gitignore index 5d381cc..80773fa 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +src/config.py \ No newline at end of file diff --git a/src/example_config.py b/src/example_config.py new file mode 100644 index 0000000..6b2dff6 --- /dev/null +++ b/src/example_config.py @@ -0,0 +1,3 @@ +PWD_URL = "https://my-domain/ABunchOfRandomCharactersBecauseThisIsNotReallyImportant.file" +DISK = "/dev/sda" +MNT_LOCATION = "/mnt" diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..d64cab1 --- /dev/null +++ b/src/main.py @@ -0,0 +1,39 @@ +from datetime import datetime +import subprocess +import requests +import os + +from . import config + +def log(*args, **kwargs): + date = datetime.now().strftime('%d-%b-%Y %H:%M:%S') + print(f"[{date}]", *args, **kwargs) + + +if not os.path.exists(config.DISK): + log_error(f"Drive {config.DISK} not present on the system") + +passwd = requests.get(config.PWD_URL).text +log("Got password :", passwd) + +subprocess.call([ + "cryptsetup", "luksOpen", + "--key-description", passwd, + config.DISK, "backup" +]) + +subprocess.call([ + "mount", "/dev/mapper/backup", + config.MNT_LOCATION +]) + +log("Succesfully mounted, doing the backup stuff") + +subprocess.call([ + "umount", config.MNT_LOCATION +]) + +subprocess.call([ + "cryptsetup", "luksClose", + "/dev/mapper/backup" +])