fixed deleting old files
This commit is contained in:
parent
33749c149c
commit
bd8b63bc8d
@ -50,9 +50,12 @@ def main():
|
||||
if sys.argv[1:]:
|
||||
config_file = sys.argv[1]
|
||||
remotes, jobs, settings = load_config(config_file)
|
||||
for job in jobs:
|
||||
for index, job in enumerate(jobs):
|
||||
src = create_remote(remotes[job["src"]], settings)
|
||||
dest = create_remote(remotes[job["dest"]], settings)
|
||||
if index == 0:
|
||||
#delete old files (not very adaptable, cant handle dirs in dirs)
|
||||
dest.delete_remote_zips("/home/nonroot/backups")
|
||||
if 'demo_' in job["job_name"]:
|
||||
source_files = src.list_dir()
|
||||
distribute_files(source_files, dest)
|
||||
@ -66,7 +69,6 @@ def main():
|
||||
logging.warning(log_msg)
|
||||
sys.exit(1)
|
||||
src.delete_local_zip(zip_file_path)
|
||||
dest.delete_remote_zips(zip_file_path)
|
||||
elif "mysqldump" in job["job_name"]:
|
||||
src.remote_channel_command(job, "mysqldump")
|
||||
zipname = src.remote_channel_command(job, "zip_mysqldump")
|
||||
|
@ -180,11 +180,16 @@ class sftp_remote:
|
||||
self.delete_file(last_modified, pathfile, 45)
|
||||
self.disconnect()
|
||||
|
||||
def delete_remote_zips(self, zip_file_path):
|
||||
def delete_remote_zips(self, backups_dir):
|
||||
self.connect()
|
||||
if zip_file_path.endswith(".zip"):
|
||||
pathfile, last_modified = self.change_path(zip_file_path)
|
||||
self.delete_file(last_modified, pathfile, 10)
|
||||
for directories in self.sftp.listdir(backups_dir):
|
||||
for files in self.sftp.listdir(f'{backups_dir}/{directories}'):
|
||||
pathfile = f'{backups_dir}/{directories}/{files}'
|
||||
if not pathfile.endswith(".zip"):
|
||||
continue
|
||||
utime = self.sftp.stat(pathfile).st_mtime
|
||||
last_modified = datetime.fromtimestamp(utime)
|
||||
self.delete_file(last_modified, pathfile, 10)
|
||||
self.disconnect()
|
||||
|
||||
def delete_remote_zip_temp(self, zipname):
|
||||
@ -195,4 +200,3 @@ class sftp_remote:
|
||||
def delete_local_zip(self, local_zip_path_name):
|
||||
os.remove(local_zip_path_name)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user