1.0.1 Improvements
This commit is contained in:
parent
f5e2673f72
commit
3834aba585
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
backups/flosight/*
|
||||
backups/token-tracking/*
|
||||
@ -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)
|
||||
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]}")
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user