diff --git a/man/simple_backup.1 b/man/simple_backup.1 index 9c5f125..c7d31d3 100644 --- a/man/simple_backup.1 +++ b/man/simple_backup.1 @@ -62,6 +62,16 @@ Don't use systemd journal for logging .SH CONFIGURATION An example configuration file is provided at \(aq/etc/simple_backup/simple_backup.conf\(aq. Copy it to the default location ($HOME/.config/simple_backup) and edit it as needed. +.SH EXIT STATUS +.TP +.B 0 +The backup was completed without errors +.TP +.B 1 +No valid inputs selected for backup +.TP +.B 2 +Backup failed because output directory for storing the backup does not exist .SH SEE ALSO .BR rsync (1) .SH AUTHORS diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index c12b4eb..3989f0b 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -16,7 +16,6 @@ from glob import glob from dotenv import load_dotenv - try: from systemd import journal except ImportError: @@ -97,24 +96,24 @@ class Backup: if self.inputs is None or len(self.inputs) == 0: logger.info('No existing files or directories specified for backup. Nothing to do') - return False + return 1 if self.output is None: logger.critical('No output path specified. Use -o argument or specify output path in configuration file') - return False + return 2 if not os.path.isdir(self.output): logger.critical('Output path for backup does not exist') - return False + return 2 self.output = os.path.abspath(self.output) if self.keep is None: self.keep = -1 - return True + return 0 # Function to create the actual backup directory def create_backup_dir(self): @@ -347,12 +346,14 @@ def simple_backup(): backup = Backup(inputs, output, exclude, keep, backup_options, remove_before=args.remove_before_backup) - if backup.check_params(): + return_code = backup.check_params() + + if return_code == 0: backup.run() return 0 - return 1 + return return_code if __name__ == '__main__':