commit f5e2673f72aed5be294c6cbbe690d4bfd6ba46c3 Author: Vivek Teega Date: Fri Jun 25 05:01:07 2021 +0000 1.0.0 First commit diff --git a/README.m b/README.m new file mode 100644 index 0000000..e8fa80b --- /dev/null +++ b/README.m @@ -0,0 +1 @@ +# automated-backup-scripts diff --git a/flosight_backup.py b/flosight_backup.py new file mode 100644 index 0000000..253094d --- /dev/null +++ b/flosight_backup.py @@ -0,0 +1,32 @@ +import subprocess +import sys +import datetime +import os, pdb + +current_time = datetime.datetime.now() +backup_directory = f"{os.getcwd()}/backups/flosight/" + +def make_archive(source, destination): + base = os.path.basename(destination) + name = base.split('.')[0] + format = base.split('.')[1] + archive_from = os.path.dirname(source) + archive_to = os.path.basename(source.strip(os.sep)) + shutil.make_archive(name, format, archive_from, archive_to) + shutil.move('%s.%s'%(name,format), 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) + + +#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 diff --git a/initiate_backup.py b/initiate_backup.py new file mode 100644 index 0000000..0fee489 --- /dev/null +++ b/initiate_backup.py @@ -0,0 +1,36 @@ +import shutil +import datetime +import glob,os +import pdb + +def make_archive(source, destination): + base = os.path.basename(destination) + name = base.split('.')[0] + format = base.split('.')[1] + archive_from = os.path.dirname(source) + archive_to = os.path.basename(source.strip(os.sep)) + shutil.make_archive(name, format, archive_from, archive_to) + 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()) +# Get list of all files only in the given directory +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) +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) +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