From 3834aba5857b1305887b8da238cfc066d4683cc1 Mon Sep 17 00:00:00 2001 From: Vivek Teega Date: Sat, 26 Jun 2021 10:20:01 +0000 Subject: [PATCH] 1.0.1 Improvements --- .gitignore | 2 ++ flosight_backup.py => flosight-backup.py | 25 ++++++++++++------- ...iate_backup.py => token-tracking-backup.py | 6 +++-- 3 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 .gitignore rename flosight_backup.py => flosight-backup.py (60%) rename initiate_backup.py => token-tracking-backup.py (99%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bcf80ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +backups/flosight/* +backups/token-tracking/* diff --git a/flosight_backup.py b/flosight-backup.py similarity index 60% rename from flosight_backup.py rename to flosight-backup.py index 253094d..5331645 100644 --- a/flosight_backup.py +++ b/flosight-backup.py @@ -1,10 +1,14 @@ import subprocess import sys import datetime -import os, pdb +import os, pdb, time +from stat import S_ISREG, ST_CTIME, ST_MODE +from pathlib import Path -current_time = datetime.datetime.now() + +current_time = datetime.datetime.now() backup_directory = f"{os.getcwd()}/backups/flosight/" +container_id = "e960eb376abd" def make_archive(source, destination): base = os.path.basename(destination) @@ -17,16 +21,19 @@ def make_archive(source, destination): os.chdir(os.getcwd()) # Get list of all files only in the given directory -pdb.set_trace() list_of_files = filter( lambda x: os.path.isfile(os.path.join(backup_directory, x)),os.listdir(backup_directory)) # Sort list of files based on last modification time in ascending order list_of_files = sorted( list_of_files, key = lambda x: os.path.getmtime(os.path.join(backup_directory, x))) -print(list_of_files) - +print(f"List of files is :\n{list_of_files}") #result = subprocess.run([sys.executable, "-c", f"sudo docker cp c640f68b91be:/data/ /home/production/deployed/automated-backup-scripts/backups/flosight/flosight-backup-{current_time.year}-{current_time.month}-{current_time.day}-{current_time.hour}-{current_time.minute}-{current_time.second}"], capture_output=True, text=True) -#result = subprocess.check_output(f"sudo docker cp c640f68b91be:/data/ /home/production/deployed/automated-backup-scripts/backups/flosight/flosight-backup-{current_time.year}-{current_time.month}-{current_time.day}-{current_time.hour}-{current_time.minute}-{current_time.second}", stderr=subprocess.STDOUT, shell=True) -pdb.set_trace() -print("stdout:", result.stdout) -print("stderr:", result.stderr) \ No newline at end of file +folder_name = f"{os.getcwd()}/backups/flosight/flosight-backup-{current_time.year}-{current_time.month}-{current_time.day}-{current_time.hour}-{current_time.minute}-{current_time.second}" +result = subprocess.check_output(f"sudo docker cp {container_id}:/data/ {folder_name}", stderr=subprocess.STDOUT, shell=True) +#print("stdout:", result.stdout) +#print("stderr:", result.stderr) +make_archive(folder_name, f"{folder_name}.zip") +shutil.rmtree(folder_name) + +if len(list_of_files) >= 3: + os.remove(f"{os.getcwd()}/backups/flosight/{list_of_files[0]}") diff --git a/initiate_backup.py b/token-tracking-backup.py similarity index 99% rename from initiate_backup.py rename to token-tracking-backup.py index 0fee489..75e5be8 100644 --- a/initiate_backup.py +++ b/token-tracking-backup.py @@ -13,7 +13,6 @@ def make_archive(source, destination): shutil.move('%s.%s'%(name,format), destination) # using now() to get current time -current_time = datetime.datetime.now() backup_directory = f"{os.getcwd()}/backups/token-tracking" os.chdir(os.getcwd()) @@ -28,9 +27,12 @@ pdb.set_trace() # Flo Token Tracking folder_location = '/home/production/deployed/flo-token-tracking-apiErrorHandling' #shutil.make_archive(f"flo-token-tracking-backup-{current_time.year}-{current_time.month}-{current_time.day}-{current_time.hour}-{current_time.minute}-{current_time.second}", 'zip', folder_location) +current_time = datetime.datetime.now() make_archive(folder_location, f"{os.getcwd()}/backups/flo-token-tracking-backup-{current_time.year}-{current_time.month}-{current_time.day}-{current_time.hour}-{current_time.minute}-{current_time.second}.zip") if len(list_of_files) >= 3: os.remove(f"{os.getcwd()}/backups/token-tracking/{list_of_files[0]}") -# Flosight +# Flosight + +