202202# Do not stop on error?
203203DO_NOT_STOP_ON_ERROR = os .environ .get ('DO_NOT_STOP_ON_ERROR' , '' )
204204
205+ # The backup root (where backups can be found)
206+ BACKUP_ROOT_DIR = '/backup'
205207# The recovery root dir, where backups are unpacked.
206208RECOVERY_ROOT_DIR = '/recovery'
207209DECOMPRESSED_RECOVERY_NAME = 'recovery'
@@ -397,6 +399,9 @@ def error(error_no):
397399if not os .path .isdir (RECOVERY_ROOT_DIR ):
398400 print ('--] Recovery root directory does not exist (%s). Leaving.' % RECOVERY_ROOT_DIR )
399401 error (ERROR_NO_ROOT )
402+ if not os .path .isdir (BACKUP_ROOT_DIR ):
403+ print ('--] Backup root directory does not exist (%s). Leaving.' % BACKUP_ROOT_DIR )
404+ error (ERROR_NO_ROOT )
400405
401406#####
402407# 1 #
@@ -405,7 +410,7 @@ def error(error_no):
405410 RCLONE_START_TIME = datetime .now ()
406411 print ('--] Running rclone [%s]' % RCLONE_START_TIME )
407412
408- RCLONE_CMD = 'rclone sync remote:%s %s' % (USE_RCLONE_BUCKET_AND_PATH , RECOVERY_ROOT_DIR )
413+ RCLONE_CMD = 'rclone sync remote:%s %s' % (USE_RCLONE_BUCKET_AND_PATH , BACKUP_ROOT_DIR )
409414 print (" $" , RCLONE_CMD )
410415
411416 COMPLETED_PROCESS = subprocess .run (RCLONE_CMD , shell = True ,
@@ -430,7 +435,7 @@ def error(error_no):
430435# A dictionary of backup files and their directories.
431436LATEST_BACKUP = None
432437KNOWN_BACKUPS = {}
433- FILE_SEARCH = os .path .join (RECOVERY_ROOT_DIR , '**' , BACKUP_FILE_PREFIX + '*' )
438+ FILE_SEARCH = os .path .join (BACKUP_ROOT_DIR , '**' , BACKUP_FILE_PREFIX + '*' )
434439BACKUPS = glob .glob (FILE_SEARCH )
435440for BACKUP in BACKUPS :
436441 FILENAME = os .path .basename (BACKUP )
@@ -542,8 +547,6 @@ def error(error_no):
542547 if COMPLETED_PROCESS .stderr :
543548 print ('--] stderr follows...' )
544549 print (COMPLETED_PROCESS .stderr .decode ("utf-8" ).strip ())
545- # Remove the current backup
546- os .remove (BACKUP )
547550 print ('--] Leaving' )
548551 write_termination_message ('Unpack failed' )
549552 sys .exit (0 )
0 commit comments