From adca39a4cf2ed80beb8dc10b424daa439c7e3df7 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 5 Nov 2024 18:23:43 -0500 Subject: [PATCH] 2024-11-05 Fred Gleason * Added code to display the metadata of the proposed backup to restore in the warning message in rdautorest(8). Signed-off-by: Fred Gleason --- ChangeLog | 3 ++ utils/rdautorest/rdautorest.py | 55 +++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index aeb3e3b0..dafd2e70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24935,3 +24935,6 @@ 2024-11-05 Fred Gleason * Modified rdautoback(8) so as to be able to take multiple mount point arguments. +2024-11-05 Fred Gleason + * Added code to display the metadata of the proposed backup + to restore in the warning message in rdautorest(8). diff --git a/utils/rdautorest/rdautorest.py b/utils/rdautorest/rdautorest.py index 8206d79b..d5360af7 100755 --- a/utils/rdautorest/rdautorest.py +++ b/utils/rdautorest/rdautorest.py @@ -48,16 +48,6 @@ else: print(USAGE) exit(1) -if(not yes): - print('WARNING: This operation will COMPLETELY OVERWRITE the existing') - print(' Rivendell data on this system, replacing it with the') - print(' contents of the specified data backup. This operation') - print(' cannot be undone!') - print('') - resp=input(' Are you sure you want to proceed (y/N)?') - if((resp.upper()!='Y')and(resp.upper()!='YES')): - exit(0) - # # Load rd.conf(5) # @@ -68,20 +58,45 @@ rd_config.read_file(open('/etc/rd.conf')) # Open the syslog # syslog.openlog('rdautorest.py',logoption=syslog.LOG_PID|syslog.LOG_PERROR,facility=int(rd_config.get('Identity','SyslogFacility',fallback=syslog.LOG_USER))) -syslog.syslog(syslog.LOG_INFO,'Starting Rivendell restore from "'+mountpoint+'"') - # # Mount backup device # -result=os.system(command='findmnt '+mountpoint) -if(os.WEXITSTATUS(result)!=0): - Path(mountpoint).mkdir(parents=True,exist_ok=True) - result=os.system(command='mount '+mountpoint) - if(os.WEXITSTATUS(result)!=0): - syslog.syslog(syslog.LOG_ERR,'unable to mount backup drive') - exit(1) - os.system(command='sleep 5') +Path(mountpoint).mkdir(parents=True,exist_ok=True) +result=os.WEXITSTATUS(os.system(command='mount '+mountpoint+" 2> /dev/null")) +if((result!=0)and(result!=64)): + syslog.syslog(syslog.LOG_ERR,'unable to mount backup drive') + exit(1) +os.system(command='sleep 5') + +# +# Print warning message +# +if(not yes): + try: + with open(mountpoint+'/INFO.txt','r') as f: + print('WARNING!') + print('This operation will COMPLETELY OVERWRITE the existing') + print('Rivendell data on this system, replacing it with the') + print('contents of the following data backup:') + print() + print(f.read()) + f.close() + print('This operation cannot be undone!') + except FileNotFoundError: + print('WARNING!') + print('This operation will COMPLETELY OVERWRITE the existing') + print('Rivendell data on this system, replacing it with the') + print('contents of the specified data backup. This operation') + print('cannot be undone!') + print('') + resp=input('Are you sure you want to proceed (y/N)?') + if((resp.upper()!='Y')and(resp.upper()!='YES')): + os.system(command='umount '+mountpoint) + os.rmdir(mountpoint) + exit(0) + +syslog.syslog(syslog.LOG_INFO,'Starting Rivendell restore from "'+mountpoint+'"') # # Stop Rivendell service