Initial code commit

This commit is contained in:
augustin64 2024-11-16 15:47:12 +01:00
parent c8a14414ad
commit c721144f75
3 changed files with 43 additions and 0 deletions

1
.gitignore vendored
View File

@ -160,3 +160,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
src/config.py

3
src/example_config.py Normal file
View File

@ -0,0 +1,3 @@
PWD_URL = "https://my-domain/ABunchOfRandomCharactersBecauseThisIsNotReallyImportant.file"
DISK = "/dev/sda"
MNT_LOCATION = "/mnt"

39
src/main.py Normal file
View File

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