Merge branch 'master' into development
This commit is contained in:
commit
d1b429d37a
@ -83,6 +83,9 @@ if saving bandwith is needed.
|
||||
Remove old backups (if necessary) before creating the new backup. Useful to free some space
|
||||
before performing the backup.
|
||||
Default behavior is to remove old backups after successfully completing the backup.
|
||||
.TP
|
||||
.B \-\-no\-syslog
|
||||
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.
|
||||
|
@ -1,20 +1,20 @@
|
||||
# Example config file for simple_backup
|
||||
|
||||
[backup]
|
||||
# Input directories. Use a comma to separate items
|
||||
# Files and directories to backup. Multiple items can be separated using a comma (','). It is possible to use wildcards (i.e. '*' to match multiple characters and '~' for the user's home directory).
|
||||
inputs=/home/my_home,/etc
|
||||
|
||||
# Output directory
|
||||
# Output directory.
|
||||
backup_dir=/media/Backup
|
||||
|
||||
# Exclude patterns. Use a comma to separate items
|
||||
exclude=.gvfs,.local/share/gvfs-metadata,.cache,.dbus,.Trash,.local/share/Trash,.macromedia,.adobe,.recently-used,.recently-used.xbel,.thumbnails
|
||||
# Files, directories and patterns to exclude from the backup. Multiple items can be separated using a comma.
|
||||
exclude=*.bak
|
||||
|
||||
# Number of snapshots to keep (use -1 to keep all)
|
||||
# Number of old backups (i.e. excluding the one that's being created) to keep (use -1 to keep all)
|
||||
keep=-1
|
||||
|
||||
# Uncomment the following section to enable backup to remote server through ssh
|
||||
#[server]
|
||||
#host=
|
||||
#username=
|
||||
#ssh_keyfile=
|
||||
# [server]
|
||||
# host=
|
||||
# username=
|
||||
# ssh_keyfile=
|
||||
|
@ -26,6 +26,7 @@ from subprocess import Popen, PIPE, STDOUT
|
||||
from datetime import datetime
|
||||
from tempfile import mkstemp
|
||||
from getpass import getpass
|
||||
from glob import glob
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import paramiko
|
||||
@ -52,6 +53,7 @@ if euid == 0:
|
||||
user = os.getenv('SUDO_USER')
|
||||
homedir = os.path.expanduser(f'~{user}')
|
||||
else:
|
||||
user = os.getenv('USER')
|
||||
homedir = os.getenv('HOME')
|
||||
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
@ -501,12 +503,27 @@ def _parse_arguments():
|
||||
parser.add_argument('-z', '--compress', action='store_true', help='Compress data during the transfer')
|
||||
parser.add_argument('--remove-before-backup', action='store_true',
|
||||
help='Remove old backups before executing the backup, instead of after')
|
||||
parser.add_argument('--no-syslog', action='store_true', help='Disable systemd journal logging')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def _expand_inputs(inputs):
|
||||
expanded_inputs = []
|
||||
|
||||
for i in inputs:
|
||||
i_ex = glob(os.path.expanduser(i.replace('~', f'~{user}')))
|
||||
|
||||
if len(i_ex) == 0:
|
||||
logger.warning('No file or directory matching input %s. Skipping...', i)
|
||||
else:
|
||||
expanded_inputs.extend(glob(os.path.expanduser(i.replace('~', f'~{user}'))))
|
||||
|
||||
return expanded_inputs
|
||||
|
||||
|
||||
def _read_config(config_file):
|
||||
if not os.path.isfile(config_file):
|
||||
logger.warning('Config file %s does not exist', config_file)
|
||||
@ -518,7 +535,10 @@ def _read_config(config_file):
|
||||
|
||||
inputs = config.get('backup', 'inputs')
|
||||
inputs = inputs.split(',')
|
||||
inputs = _expand_inputs(inputs)
|
||||
inputs = list(set(inputs))
|
||||
output = config.get('backup', 'backup_dir')
|
||||
output = os.path.expanduser(output.replace('~', f'~{user}'))
|
||||
exclude = config.get('backup', 'exclude')
|
||||
exclude = exclude.split(',')
|
||||
keep = config.getint('backup', 'keep')
|
||||
@ -560,6 +580,13 @@ def simple_backup():
|
||||
"""Main"""
|
||||
|
||||
args = _parse_arguments()
|
||||
|
||||
if args.no_syslog:
|
||||
try:
|
||||
logger.removeHandler(j_handler)
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
inputs, output, exclude, keep, host, username, ssh_keyfile = _read_config(args.config)
|
||||
|
||||
if args.input is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user