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
|
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
|
# 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
|
# but with asynnetrical structure, cache and logs in subfolders
|
||||||
@ -23,7 +17,11 @@ except:
|
|||||||
# if not, use the first we have permissions for
|
# if not, use the first we have permissions for
|
||||||
# after we decide which to use, fix it in settings to avoid future heuristics
|
# 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")
|
usrfol = pthj(HOME_DIR,"maloja")
|
||||||
etccfg = '/etc/maloja'
|
etccfg = '/etc/maloja'
|
||||||
varlib = '/var/lib/maloja'
|
varlib = '/var/lib/maloja'
|
||||||
@ -49,22 +47,22 @@ dir_settings = {
|
|||||||
dir_options = {
|
dir_options = {
|
||||||
"config":[
|
"config":[
|
||||||
"/etc/maloja",
|
"/etc/maloja",
|
||||||
pthj(HOME_DIR,"maloja")
|
usrfol
|
||||||
],
|
],
|
||||||
"state":[
|
"state":[
|
||||||
"/var/lib/maloja",
|
"/var/lib/maloja",
|
||||||
"/etc/maloja",
|
"/etc/maloja",
|
||||||
pthj(HOME_DIR,"maloja")
|
usrfol
|
||||||
],
|
],
|
||||||
"logs":[
|
"logs":[
|
||||||
"/var/log/maloja",
|
"/var/log/maloja",
|
||||||
"/etc/maloja/logs",
|
"/etc/maloja/logs",
|
||||||
pthj(HOME_DIR,"maloja","logs")
|
pthj(usrfol,"logs")
|
||||||
],
|
],
|
||||||
"cache":[
|
"cache":[
|
||||||
"/var/cache/maloja",
|
"/var/cache/maloja",
|
||||||
"/etc/maloja/cache",
|
"/etc/maloja/cache",
|
||||||
pthj(HOME_DIR,"maloja","cache")
|
pthj(usrfol,"cache")
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,35 +9,41 @@ from doreah.logging import log
|
|||||||
|
|
||||||
|
|
||||||
user_files = {
|
user_files = {
|
||||||
"minimal":[
|
"minimal":{
|
||||||
"rules/*.tsv",
|
"rules":["*.tsv"],
|
||||||
"scrobbles"
|
"scrobbles":["*.tsv"]
|
||||||
],
|
},
|
||||||
"full":[
|
"full":{
|
||||||
"clients/authenticated_machines.tsv",
|
"clients":["authenticated_machines.tsv"],
|
||||||
"images/artists",
|
"images":["artists","tracks"],
|
||||||
"images/tracks",
|
"settings":["settings.ini"]
|
||||||
"settings/settings.ini"
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def backup(folder,level="full"):
|
def backup(folder,level="full"):
|
||||||
|
print(folder)
|
||||||
|
|
||||||
selected_files = user_files["minimal"] if level == "minimal" else user_files["minimal"] + user_files["full"]
|
selected_files = user_files["minimal"] if level == "minimal" else {**user_files["minimal"], **user_files["full"]}
|
||||||
real_files = []
|
real_files = {cat:[] for cat in selected_files}
|
||||||
for g in selected_files:
|
for cat in selected_files:
|
||||||
real_files += glob.glob(datadir(g))
|
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...")
|
log("Creating backup of " + str(len(real_files)) + " files...")
|
||||||
|
|
||||||
|
from pprint import pprint
|
||||||
|
pprint(real_files)
|
||||||
|
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
timestr = now.strftime("%Y_%m_%d_%H_%M_%S")
|
timestr = now.strftime("%Y_%m_%d_%H_%M_%S")
|
||||||
filename = "maloja_backup_" + timestr + ".tar.gz"
|
filename = "maloja_backup_" + timestr + ".tar.gz"
|
||||||
archivefile = os.path.join(folder,filename)
|
archivefile = os.path.join(folder,filename)
|
||||||
assert not os.path.exists(archivefile)
|
assert not os.path.exists(archivefile)
|
||||||
with tarfile.open(name=archivefile,mode="x:gz") as archive:
|
with tarfile.open(name=archivefile,mode="x:gz") as archive:
|
||||||
for f in real_files:
|
for cat in real_files:
|
||||||
|
for f in real_files[cat]:
|
||||||
p = PurePath(f)
|
p = PurePath(f)
|
||||||
r = p.relative_to(datadir())
|
r = p.relative_to(data_dir[cat]())
|
||||||
archive.add(f,arcname=r)
|
archive.add(f,arcname=os.path.join(cat,r))
|
||||||
log("Backup created!")
|
log("Backup created!")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user