mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Fixed backup
This commit is contained in:
parent
f44c3fecb2
commit
db80e1791a
@ -4,12 +4,6 @@ from doreah.settings import config as settingsconfig
|
||||
|
||||
pthj = os.path.join
|
||||
|
||||
try:
|
||||
HOME_DIR = os.environ["XDG_DATA_HOME"].split(":")[0]
|
||||
assert os.path.exists(HOME_DIR)
|
||||
except:
|
||||
HOME_DIR = os.path.join(os.environ["HOME"],".local/share/")
|
||||
|
||||
|
||||
# if DATA_DIRECTORY is specified, this is the directory to use for EVERYTHING, no matter what
|
||||
# but with asynnetrical structure, cache and logs in subfolders
|
||||
@ -23,7 +17,11 @@ except:
|
||||
# if not, use the first we have permissions for
|
||||
# after we decide which to use, fix it in settings to avoid future heuristics
|
||||
|
||||
|
||||
try:
|
||||
HOME_DIR = os.environ["XDG_DATA_HOME"].split(":")[0]
|
||||
assert os.path.exists(HOME_DIR)
|
||||
except:
|
||||
HOME_DIR = os.path.join(os.environ["HOME"],".local/share/")
|
||||
usrfol = pthj(HOME_DIR,"maloja")
|
||||
etccfg = '/etc/maloja'
|
||||
varlib = '/var/lib/maloja'
|
||||
@ -49,22 +47,22 @@ dir_settings = {
|
||||
dir_options = {
|
||||
"config":[
|
||||
"/etc/maloja",
|
||||
pthj(HOME_DIR,"maloja")
|
||||
usrfol
|
||||
],
|
||||
"state":[
|
||||
"/var/lib/maloja",
|
||||
"/etc/maloja",
|
||||
pthj(HOME_DIR,"maloja")
|
||||
usrfol
|
||||
],
|
||||
"logs":[
|
||||
"/var/log/maloja",
|
||||
"/etc/maloja/logs",
|
||||
pthj(HOME_DIR,"maloja","logs")
|
||||
pthj(usrfol,"logs")
|
||||
],
|
||||
"cache":[
|
||||
"/var/cache/maloja",
|
||||
"/etc/maloja/cache",
|
||||
pthj(HOME_DIR,"maloja","cache")
|
||||
pthj(usrfol,"cache")
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -9,35 +9,41 @@ from doreah.logging import log
|
||||
|
||||
|
||||
user_files = {
|
||||
"minimal":[
|
||||
"rules/*.tsv",
|
||||
"scrobbles"
|
||||
],
|
||||
"full":[
|
||||
"clients/authenticated_machines.tsv",
|
||||
"images/artists",
|
||||
"images/tracks",
|
||||
"settings/settings.ini"
|
||||
]
|
||||
"minimal":{
|
||||
"rules":["*.tsv"],
|
||||
"scrobbles":["*.tsv"]
|
||||
},
|
||||
"full":{
|
||||
"clients":["authenticated_machines.tsv"],
|
||||
"images":["artists","tracks"],
|
||||
"settings":["settings.ini"]
|
||||
}
|
||||
}
|
||||
|
||||
def backup(folder,level="full"):
|
||||
print(folder)
|
||||
|
||||
selected_files = user_files["minimal"] if level == "minimal" else user_files["minimal"] + user_files["full"]
|
||||
real_files = []
|
||||
for g in selected_files:
|
||||
real_files += glob.glob(datadir(g))
|
||||
selected_files = user_files["minimal"] if level == "minimal" else {**user_files["minimal"], **user_files["full"]}
|
||||
real_files = {cat:[] for cat in selected_files}
|
||||
for cat in selected_files:
|
||||
catfolder = data_dir[cat]
|
||||
for g in selected_files[cat]:
|
||||
real_files[cat] += glob.glob(catfolder(g))
|
||||
|
||||
log("Creating backup of " + str(len(real_files)) + " files...")
|
||||
|
||||
from pprint import pprint
|
||||
pprint(real_files)
|
||||
|
||||
now = datetime.utcnow()
|
||||
timestr = now.strftime("%Y_%m_%d_%H_%M_%S")
|
||||
filename = "maloja_backup_" + timestr + ".tar.gz"
|
||||
archivefile = os.path.join(folder,filename)
|
||||
assert not os.path.exists(archivefile)
|
||||
with tarfile.open(name=archivefile,mode="x:gz") as archive:
|
||||
for f in real_files:
|
||||
p = PurePath(f)
|
||||
r = p.relative_to(datadir())
|
||||
archive.add(f,arcname=r)
|
||||
for cat in real_files:
|
||||
for f in real_files[cat]:
|
||||
p = PurePath(f)
|
||||
r = p.relative_to(data_dir[cat]())
|
||||
archive.add(f,arcname=os.path.join(cat,r))
|
||||
log("Backup created!")
|
||||
|
Loading…
Reference in New Issue
Block a user