Committing the script.
This commit is contained in:
47
config-backup.py
Normal file
47
config-backup.py
Normal file
@ -0,0 +1,47 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import os
|
||||
import datetime
|
||||
|
||||
now = datetime.datetime.now()
|
||||
CONFIGPATHS = [
|
||||
("100","nextcloud","/srv/nextcloud/config"),
|
||||
("105","authdocker","/root"),
|
||||
("107","homeautomation","/root"),
|
||||
("109","immich-vfs","/root"),
|
||||
]
|
||||
def main():
|
||||
for lxc in CONFIGPATHS:
|
||||
print(lxc)
|
||||
newdir = Path(f"{lxc[0]}-{lxc[1]}{lxc[2].replace('/','.')}")
|
||||
try:
|
||||
newdir.mkdir()
|
||||
except FileExistsError as e:
|
||||
pass
|
||||
finally:
|
||||
configpath = f"/main/subvol-{lxc[0]}-disk-0{lxc[2]}/"
|
||||
try:
|
||||
shutil.copytree(configpath, newdir, dirs_exist_ok=True,
|
||||
ignore=__ignore_dirs)
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
pass
|
||||
|
||||
subprocess.run(["git","checkout","-b","200-19"])
|
||||
subprocess.run(["git","add","."])
|
||||
subprocess.run(["git","commit","-m",f"Backup for {now}"])
|
||||
subprocess.run(["git","push","-u","origin","200-19"])
|
||||
|
||||
def __ignore_dirs(path, names):
|
||||
dirs = [".git", ".local", ".cache"]
|
||||
ignoredirs = []
|
||||
for file in os.listdir(path):
|
||||
if file in dirs:
|
||||
ignoredirs.append(file)
|
||||
return tuple(ignoredirs)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user