Fix small bugs
This commit is contained in:
parent
b4294a5792
commit
da07c602b5
140
simple-backup.py
140
simple-backup.py
@ -12,7 +12,8 @@ import subprocess
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
|
|
||||||
class Backup():
|
|
||||||
|
class Backup:
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Backup, self).__init__(*args, **kwargs)
|
super(Backup, self).__init__(*args, **kwargs)
|
||||||
@ -36,7 +37,8 @@ class Backup():
|
|||||||
self.n_in = 0
|
self.n_in = 0
|
||||||
|
|
||||||
# Help function
|
# Help function
|
||||||
def help_function(self):
|
@staticmethod
|
||||||
|
def help_function():
|
||||||
print('simple_backup, version 2.0.0')
|
print('simple_backup, version 2.0.0')
|
||||||
print('')
|
print('')
|
||||||
print('Usage: {} [OPTIONS]'.format(argv[0]))
|
print('Usage: {} [OPTIONS]'.format(argv[0]))
|
||||||
@ -85,12 +87,12 @@ class Backup():
|
|||||||
try:
|
try:
|
||||||
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(self.homedir))
|
print('Failed to create logs in {}'.format(self.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(self.warn_path)
|
os.remove(self.warn_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary file')
|
print('Failed to remove temporary file')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -113,12 +115,12 @@ class Backup():
|
|||||||
try:
|
try:
|
||||||
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(self.homedir))
|
print('Failed to create logs in {}'.format(self.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(self.warn_path)
|
os.remove(self.warn_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary file')
|
print('Failed to remove temporary file')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -139,7 +141,6 @@ class Backup():
|
|||||||
if line[:7] == 'inputs=':
|
if line[:7] == 'inputs=':
|
||||||
line = line[7:].rstrip()
|
line = line[7:].rstrip()
|
||||||
input_values = line.split(',')
|
input_values = line.split(',')
|
||||||
n_in = 0
|
|
||||||
for i in input_values:
|
for i in input_values:
|
||||||
if not exists(i):
|
if not exists(i):
|
||||||
warn_message = 'Warning: input "' + i + '" not found. Skipping'
|
warn_message = 'Warning: input "' + i + '" not found. Skipping'
|
||||||
@ -187,14 +188,14 @@ class Backup():
|
|||||||
try:
|
try:
|
||||||
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(self.homedir))
|
print('Failed to create logs in {}'.format(self.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(self.warn_path)
|
os.remove(self.warn_path)
|
||||||
os.remove(self.inputs_path)
|
os.remove(self.inputs_path)
|
||||||
os.remove(self.exclude_path)
|
os.remove(self.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -209,7 +210,7 @@ class Backup():
|
|||||||
if islink(self.last_backup):
|
if islink(self.last_backup):
|
||||||
try:
|
try:
|
||||||
self.last_backup = os.readlink(self.last_backup)
|
self.last_backup = os.readlink(self.last_backup)
|
||||||
except:
|
except Exception:
|
||||||
self.last_backup = ''
|
self.last_backup = ''
|
||||||
err_message = 'An error occurred when reading the last_backup link. Continuing anyway'
|
err_message = 'An error occurred when reading the last_backup link. Continuing anyway'
|
||||||
print(err_message)
|
print(err_message)
|
||||||
@ -239,18 +240,18 @@ class Backup():
|
|||||||
try:
|
try:
|
||||||
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(self.homedir))
|
print('Failed to create logs in {}'.format(self.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(self.warn_path)
|
os.remove(self.warn_path)
|
||||||
os.remove(self.inputs_path)
|
os.remove(self.inputs_path)
|
||||||
os.remove(self.exclude_path)
|
os.remove(self.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
except:
|
except Exception:
|
||||||
log_message = str(datetime.now()) + 'Backup failed (see errors.log)'
|
log_message = str(datetime.now()) + 'Backup failed (see errors.log)'
|
||||||
self.logfile.write(log_message)
|
self.logfile.write(log_message)
|
||||||
self.logfile.write('\n')
|
self.logfile.write('\n')
|
||||||
@ -266,20 +267,18 @@ class Backup():
|
|||||||
try:
|
try:
|
||||||
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(self.homedir))
|
print('Failed to create logs in {}'.format(self.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(self.warn_path)
|
os.remove(self.warn_path)
|
||||||
os.remove(self.inputs_path)
|
os.remove(self.inputs_path)
|
||||||
os.remove(self.exclude_path)
|
os.remove(self.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
# Function to parse options
|
# Function to parse options
|
||||||
def parse_options(self):
|
def parse_options(self):
|
||||||
# Create temporary files
|
# Create temporary files
|
||||||
@ -294,9 +293,9 @@ class Backup():
|
|||||||
while i < len(argv):
|
while i < len(argv):
|
||||||
var = argv[i]
|
var = argv[i]
|
||||||
|
|
||||||
if var == '-h' or var == '--help':
|
if var in ['-h', '--help']:
|
||||||
self.help_function()
|
self.help_function()
|
||||||
elif var == '-i' or var == '--input':
|
elif var in ['-i', '--input']:
|
||||||
val = argv[i+1]
|
val = argv[i+1]
|
||||||
while i < len(argv) - 1 and val[0] != '-':
|
while i < len(argv) - 1 and val[0] != '-':
|
||||||
inp = val
|
inp = val
|
||||||
@ -313,7 +312,7 @@ class Backup():
|
|||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
val = argv[i+1]
|
val = argv[i+1]
|
||||||
elif var == '-d' or var == '--directory':
|
elif var in ['-d', '--directory']:
|
||||||
self.backup_dev = argv[i+1]
|
self.backup_dev = argv[i+1]
|
||||||
self.backup_dev = abspath(self.backup_dev)
|
self.backup_dev = abspath(self.backup_dev)
|
||||||
|
|
||||||
@ -336,14 +335,14 @@ class Backup():
|
|||||||
try:
|
try:
|
||||||
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(self.homedir))
|
print('Failed to create logs in {}'.format(self.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(self.warn_path)
|
os.remove(self.warn_path)
|
||||||
os.remove(self.inputs_path)
|
os.remove(self.inputs_path)
|
||||||
os.remove(self.exclude_path)
|
os.remove(self.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -358,7 +357,7 @@ class Backup():
|
|||||||
if islink(self.last_backup):
|
if islink(self.last_backup):
|
||||||
try:
|
try:
|
||||||
self.last_backup = os.readlink(self.last_backup)
|
self.last_backup = os.readlink(self.last_backup)
|
||||||
except:
|
except Exception:
|
||||||
self.last_backup = ''
|
self.last_backup = ''
|
||||||
err_message = 'An error occurred when reading the last_backup link. Continuing anyway'
|
err_message = 'An error occurred when reading the last_backup link. Continuing anyway'
|
||||||
print(err_message)
|
print(err_message)
|
||||||
@ -390,18 +389,18 @@ class Backup():
|
|||||||
try:
|
try:
|
||||||
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(self.homedir))
|
print('Failed to create logs in {}'.format(self.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(self.warn_path)
|
os.remove(self.warn_path)
|
||||||
os.remove(self.inputs_path)
|
os.remove(self.inputs_path)
|
||||||
os.remove(self.exclude_path)
|
os.remove(self.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
except:
|
except Exception:
|
||||||
log_message = str(datetime.now()) + 'Backup failed (see errors.log)'
|
log_message = str(datetime.now()) + 'Backup failed (see errors.log)'
|
||||||
self.logfile.write(log_message)
|
self.logfile.write(log_message)
|
||||||
self.logfile.write('\n')
|
self.logfile.write('\n')
|
||||||
@ -420,20 +419,20 @@ class Backup():
|
|||||||
try:
|
try:
|
||||||
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(self.homedir))
|
print('Failed to create logs in {}'.format(self.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(self.warn_path)
|
os.remove(self.warn_path)
|
||||||
os.remove(self.inputs_path)
|
os.remove(self.inputs_path)
|
||||||
os.remove(self.exclude_path)
|
os.remove(self.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
elif var == '-e' or var == '--exclude':
|
elif var in ['-e', '--exclude']:
|
||||||
val = argv[i+1]
|
val = argv[i+1]
|
||||||
while i < len(argv) - 1 and val[0] != '-':
|
while i < len(argv) - 1 and val[0] != '-':
|
||||||
exc = val
|
exc = val
|
||||||
@ -442,22 +441,23 @@ class Backup():
|
|||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
val = argv[i+1]
|
val = argv[i+1]
|
||||||
elif var == '-k' or var == '--keep':
|
elif var in ['-k', '--keep']:
|
||||||
self.keep = int(argv[i+1])
|
self.keep = int(argv[i+1])
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
elif var == '-c' or var == '--config':
|
elif var in ['-c', '--config']:
|
||||||
self.read_conf(argv[i+1])
|
self.read_conf(argv[i+1])
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
elif var == '-s' or var == '--checksum':
|
elif var in ['-s', '--checksum']:
|
||||||
self.options = '-arcvh -H -X'
|
self.options = '-arcvh -H -X'
|
||||||
else:
|
else:
|
||||||
log_message = str(datetime.now()) + ': Backup failed (see errors.log)'
|
log_message = str(datetime.now()) + ': Backup failed (see errors.log)'
|
||||||
self.logfile.write(log_message)
|
self.logfile.write(log_message)
|
||||||
self.logfile.write('\n')
|
self.logfile.write('\n')
|
||||||
print('Backup failed')
|
print('Backup failed')
|
||||||
err_message = 'Error: Option "' + var + '" not recognised. Use "simple-backup -h" to see available options'
|
err_message = 'Error: Option "' + var +\
|
||||||
|
'" not recognised. Use "simple-backup -h" to see available options'
|
||||||
print(err_message)
|
print(err_message)
|
||||||
self.errfile.write(err_message)
|
self.errfile.write(err_message)
|
||||||
self.errfile.write('\n')
|
self.errfile.write('\n')
|
||||||
@ -471,14 +471,14 @@ class Backup():
|
|||||||
try:
|
try:
|
||||||
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
move(self.log_path, self.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
move(self.err_path, self.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(self.homedir))
|
print('Failed to create logs in {}'.format(self.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(self.warn_path)
|
os.remove(self.warn_path)
|
||||||
os.remove(self.inputs_path)
|
os.remove(self.inputs_path)
|
||||||
os.remove(self.exclude_path)
|
os.remove(self.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -488,8 +488,6 @@ class Backup():
|
|||||||
self.inputs.close()
|
self.inputs.close()
|
||||||
self.exclude.close()
|
self.exclude.close()
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def exec_(self):
|
def exec_(self):
|
||||||
print('Copying files. This may take a long time...')
|
print('Copying files. This may take a long time...')
|
||||||
|
|
||||||
@ -504,7 +502,6 @@ class Backup():
|
|||||||
|
|
||||||
subprocess.run(rsync, shell=True)
|
subprocess.run(rsync, shell=True)
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
@ -523,7 +520,7 @@ def main():
|
|||||||
# Set homedir and default options
|
# Set homedir and default options
|
||||||
try:
|
try:
|
||||||
backup.homedir = '/home/' + os.environ['SUDO_USER']
|
backup.homedir = '/home/' + os.environ['SUDO_USER']
|
||||||
except:
|
except Exception:
|
||||||
backup.homedir = expanduser('~')
|
backup.homedir = expanduser('~')
|
||||||
|
|
||||||
backup.options = '-arvh -H -X'
|
backup.options = '-arvh -H -X'
|
||||||
@ -533,7 +530,7 @@ def main():
|
|||||||
# If simple backup directory doesn't exist, create it and exit
|
# If simple backup directory doesn't exist, create it and exit
|
||||||
if not isdir(backup.homedir + '/.simple_backup'):
|
if not isdir(backup.homedir + '/.simple_backup'):
|
||||||
try:
|
try:
|
||||||
os.makedir(backup.homedir + '/.simple_backup')
|
os.mkdir(backup.homedir + '/.simple_backup')
|
||||||
log_message = 'Created directory "' + backup.homedir + '/.simple_backup".\n' +\
|
log_message = 'Created directory "' + backup.homedir + '/.simple_backup".\n' +\
|
||||||
'Copy there the sample configuration and edit it\n' +\
|
'Copy there the sample configuration and edit it\n' +\
|
||||||
'to your needs before running the backup,\n' +\
|
'to your needs before running the backup,\n' +\
|
||||||
@ -548,15 +545,15 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(backup.homedir))
|
print('Failed to create logs in {}'.format(backup.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(backup.err_path)
|
os.remove(backup.err_path)
|
||||||
os.remove(backup.warn_path)
|
os.remove(backup.warn_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create .simple_backup directory in {}'.format(backup.homedir))
|
print('Failed to create .simple_backup directory in {}'.format(backup.homedir))
|
||||||
|
|
||||||
backup.logfile.close()
|
backup.logfile.close()
|
||||||
@ -567,7 +564,7 @@ def main():
|
|||||||
os.remove(backup.log_path)
|
os.remove(backup.log_path)
|
||||||
os.remove(backup.err_path)
|
os.remove(backup.err_path)
|
||||||
os.remove(backup.warn_path)
|
os.remove(backup.warn_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -585,7 +582,7 @@ def main():
|
|||||||
backup.logfile.write(log_message)
|
backup.logfile.write(log_message)
|
||||||
backup.logfile.write('\n')
|
backup.logfile.write('\n')
|
||||||
print('Backup failed')
|
print('Backup failed')
|
||||||
err_message = 'Error: Output folder "' + backup.backup_dev.getBackupDev + '" not found'
|
err_message = 'Error: Output folder "' + backup.backup_dev + '" not found'
|
||||||
print(err_message)
|
print(err_message)
|
||||||
backup.errfile.write(err_message)
|
backup.errfile.write(err_message)
|
||||||
backup.errfile.write('\n')
|
backup.errfile.write('\n')
|
||||||
@ -597,21 +594,21 @@ def main():
|
|||||||
try:
|
try:
|
||||||
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(backup.err_path, backup.homedir + '/.simple_backup/errors.log')
|
move(backup.err_path, backup.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(backup.homedir))
|
print('Failed to create logs in {}'.format(backup.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(backup.warn_path)
|
os.remove(backup.warn_path)
|
||||||
os.remove(backup.inputs_path)
|
os.remove(backup.inputs_path)
|
||||||
os.remove(backup.exclude_path)
|
os.remove(backup.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
elif backup.n_in == 0 and backup.backup_dir == '':
|
elif backup.n_in == 0 and backup.backup_dir == '':
|
||||||
if not isdir(backup.homedir + '/.simple_backup'):
|
if not isdir(backup.homedir + '/.simple_backup'):
|
||||||
try:
|
try:
|
||||||
os.makedir(backup.homedir + '/.simple_backup')
|
os.mkdir(backup.homedir + '/.simple_backup')
|
||||||
log_message = 'Created directory "' + backup.homedir + '/.simple_backup".\n' +\
|
log_message = 'Created directory "' + backup.homedir + '/.simple_backup".\n' +\
|
||||||
'Copy there the sample configuration and edit it\n' +\
|
'Copy there the sample configuration and edit it\n' +\
|
||||||
'to your needs before running the backup,\n' +\
|
'to your needs before running the backup,\n' +\
|
||||||
@ -626,7 +623,7 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(backup.homedir))
|
print('Failed to create logs in {}'.format(backup.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -634,9 +631,9 @@ def main():
|
|||||||
os.remove(backup.warn_path)
|
os.remove(backup.warn_path)
|
||||||
os.remove(backup.inputs_path)
|
os.remove(backup.inputs_path)
|
||||||
os.remove(backup.exclude_path)
|
os.remove(backup.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create .simple_backup directory in {}'.format(backup.homedir))
|
print('Failed to create .simple_backup directory in {}'.format(backup.homedir))
|
||||||
|
|
||||||
backup.logfile.close()
|
backup.logfile.close()
|
||||||
@ -649,7 +646,7 @@ def main():
|
|||||||
os.remove(backup.warn_path)
|
os.remove(backup.warn_path)
|
||||||
os.remove(backup.inputs_path)
|
os.remove(backup.inputs_path)
|
||||||
os.remove(backup.exclude_path)
|
os.remove(backup.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -657,7 +654,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
os.remove(backup.inputs_path)
|
os.remove(backup.inputs_path)
|
||||||
os.remove(backup.exclude_path)
|
os.remove(backup.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
backup.read_conf(backup.homedir + '/.simple_backup/config')
|
backup.read_conf(backup.homedir + '/.simple_backup/config')
|
||||||
@ -679,14 +676,14 @@ def main():
|
|||||||
try:
|
try:
|
||||||
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(backup.warn_path, backup.homedir + '/.simple_backup/warnings.log')
|
move(backup.warn_path, backup.homedir + '/.simple_backup/warnings.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(backup.homedir))
|
print('Failed to create logs in {}'.format(backup.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(backup.err_path)
|
os.remove(backup.err_path)
|
||||||
os.remove(backup.inputs_path)
|
os.remove(backup.inputs_path)
|
||||||
os.remove(backup.exclude_path)
|
os.remove(backup.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(0)
|
exit(0)
|
||||||
@ -700,7 +697,7 @@ def main():
|
|||||||
if backup.keep > -1:
|
if backup.keep > -1:
|
||||||
try:
|
try:
|
||||||
dirs = os.listdir(backup.backup_dev + '/simple_backup')
|
dirs = os.listdir(backup.backup_dev + '/simple_backup')
|
||||||
except:
|
except Exception:
|
||||||
err_message = 'Failed to access backup directory'
|
err_message = 'Failed to access backup directory'
|
||||||
backup.errfile.write(err_message)
|
backup.errfile.write(err_message)
|
||||||
backup.errfile.write('\n')
|
backup.errfile.write('\n')
|
||||||
@ -713,14 +710,14 @@ def main():
|
|||||||
try:
|
try:
|
||||||
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
||||||
move(backup.err_path, backup.homedir + '.simple_backup/errors.log')
|
move(backup.err_path, backup.homedir + '.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(backup.homedir))
|
print('Failed to create logs in {}'.format(backup.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(backup.warn_path)
|
os.remove(backup.warn_path)
|
||||||
os.remove(backup.inputs_path)
|
os.remove(backup.inputs_path)
|
||||||
os.remove(backup.exclude_path)
|
os.remove(backup.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -741,7 +738,7 @@ def main():
|
|||||||
log_message = 'Removed backup: ' + dirs[i]
|
log_message = 'Removed backup: ' + dirs[i]
|
||||||
backup.logfile.write(log_message)
|
backup.logfile.write(log_message)
|
||||||
backup.logfile.write('\n')
|
backup.logfile.write('\n')
|
||||||
except:
|
except Exception:
|
||||||
err_message = 'Error while removing backup ' + dirs[i]
|
err_message = 'Error while removing backup ' + dirs[i]
|
||||||
backup.errfile.write(err_message)
|
backup.errfile.write(err_message)
|
||||||
backup.errfile.write('\n')
|
backup.errfile.write('\n')
|
||||||
@ -759,7 +756,7 @@ def main():
|
|||||||
if islink(backup.backup_dev + '/simple_backup/last_backup'):
|
if islink(backup.backup_dev + '/simple_backup/last_backup'):
|
||||||
try:
|
try:
|
||||||
os.remove(backup.backup_dev + '/simple_backup/last_backup')
|
os.remove(backup.backup_dev + '/simple_backup/last_backup')
|
||||||
except:
|
except Exception:
|
||||||
err_message = 'Failed to remove last_backup link'
|
err_message = 'Failed to remove last_backup link'
|
||||||
backup.errfile.write(err_message)
|
backup.errfile.write(err_message)
|
||||||
backup.errfile.write('\n')
|
backup.errfile.write('\n')
|
||||||
@ -767,7 +764,7 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
os.symlink(backup.backup_dir, backup.backup_dev + '/simple_backup/last_backup')
|
os.symlink(backup.backup_dir, backup.backup_dev + '/simple_backup/last_backup')
|
||||||
except:
|
except Exception:
|
||||||
err_message = 'Failed to create last_backup link'
|
err_message = 'Failed to create last_backup link'
|
||||||
backup.errfile.write(err_message)
|
backup.errfile.write(err_message)
|
||||||
backup.errfile.write('\n')
|
backup.errfile.write('\n')
|
||||||
@ -784,12 +781,12 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
move(backup.err_path, backup.homedir + '/.simple_backup/errors.log')
|
move(backup.err_path, backup.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(backup.homedir))
|
print('Failed to create logs in {}'.format(backup.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(backup.warn_path)
|
os.remove(backup.warn_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary file')
|
print('Failed to remove temporary file')
|
||||||
elif os.stat(backup.warn_path).st_size > 0:
|
elif os.stat(backup.warn_path).st_size > 0:
|
||||||
log_message = str(datetime.now()) + ': Backup finished with warnings (see warnings.log)'
|
log_message = str(datetime.now()) + ': Backup finished with warnings (see warnings.log)'
|
||||||
@ -799,18 +796,18 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
move(backup.warn_path, backup.homedir + '/.simple_backup/warnings.log')
|
move(backup.warn_path, backup.homedir + '/.simple_backup/warnings.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(backup.homedir))
|
print('Failed to create logs in {}'.format(backup.homedir))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(backup.err_path)
|
os.remove(backup.err_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary file')
|
print('Failed to remove temporary file')
|
||||||
|
|
||||||
if isfile(backup.homedir + '/.simple_backup/errors.log'):
|
if isfile(backup.homedir + '/.simple_backup/errors.log'):
|
||||||
try:
|
try:
|
||||||
os.remove(backup.homedir + '/.simple_backup/errors.log')
|
os.remove(backup.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove old logs')
|
print('Failed to remove old logs')
|
||||||
else:
|
else:
|
||||||
log_message = str(datetime.now()) + ': Backup finished'
|
log_message = str(datetime.now()) + ': Backup finished'
|
||||||
@ -821,18 +818,18 @@ def main():
|
|||||||
try:
|
try:
|
||||||
os.remove(backup.err_path)
|
os.remove(backup.err_path)
|
||||||
os.remove(backup.warn_path)
|
os.remove(backup.warn_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
if isfile(backup.homedir + '/.simple_backup/errors.log'):
|
if isfile(backup.homedir + '/.simple_backup/errors.log'):
|
||||||
try:
|
try:
|
||||||
os.remove(backup.homedir + '/.simple_backup/errors.log')
|
os.remove(backup.homedir + '/.simple_backup/errors.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove old logs')
|
print('Failed to remove old logs')
|
||||||
if isfile(backup.homedir + '/.simple_backup/warnings.log'):
|
if isfile(backup.homedir + '/.simple_backup/warnings.log'):
|
||||||
try:
|
try:
|
||||||
os.remove(backup.homedir + '/.simple_backup/warnings.log')
|
os.remove(backup.homedir + '/.simple_backup/warnings.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove old logs')
|
print('Failed to remove old logs')
|
||||||
|
|
||||||
backup.logfile.close()
|
backup.logfile.close()
|
||||||
@ -840,17 +837,18 @@ def main():
|
|||||||
# Copy log files in home directory
|
# Copy log files in home directory
|
||||||
try:
|
try:
|
||||||
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
move(backup.log_path, backup.homedir + '/.simple_backup/simple_backup.log')
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to create logs in {}'.format(backup.homedir))
|
print('Failed to create logs in {}'.format(backup.homedir))
|
||||||
|
|
||||||
# Delete temporary files
|
# Delete temporary files
|
||||||
try:
|
try:
|
||||||
os.remove(backup.inputs_path)
|
os.remove(backup.inputs_path)
|
||||||
os.remove(backup.exclude_path)
|
os.remove(backup.exclude_path)
|
||||||
except:
|
except Exception:
|
||||||
print('Failed to remove temporary files')
|
print('Failed to remove temporary files')
|
||||||
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user