Borgmatic configuration for backup
Borgmatic configuration for backup
Borgmatic configuration file to backup files and folder inside /srv/git.localhost
to remote or local repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File: /srv/git.localhost/borgmatic/borgmatic.yaml
# Purpose: Backup /srv/git.localhost directory
location:
source_directories:
- /srv/git.localhost
repositories:
- "/path/to/backup/repo"
exclude_patterns:
- /srv/git.localhost/data
storage:
archive_name_format: 'git.localhost-{now}'
encryption_passphrase: ""
ssh_command: ssh -i /root/.ssh/id_rsa
relocated_repo_access_is_ok: true
retention:
keep_hourly: 1
keep_daily: 7
keep_weekly: 4
keep_monthly: 6
keep_yearly: 1
prefix: 'git.localhost'
consistency:
checks:
- repository
- archives
hooks:
before_backup:
- echo "Starting a git.localhost backup."
after_backup:
- echo "Created a git.localhost backup."
- borg compact /path/to/backup/repo
on_error:
- echo "Error while creating a backup or running a backup hook."
To backup all services in /srv
folder, Use the below shell script with crontab
job to schedule backups.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Filename: /usr/local/sbin/borg-all.sh
# Purpose: To backup all services in /srv & /opt folder
#!/bin/bash
BORGMATIC=/usr/local/bin/borgmatic
for srv_app in /srv/*; do
if ([ -f ${srv_app}/borgmatic/app1/borgmatic.yaml ] && [ ! -d ${srv_app}/.nobackup ]); then
echo "${srv_app}";
${BORGMATIC} -c ${srv_app}/borgmatic/app1/borgmatic.yaml;
fi
done
if ([ -f /opt/borgmatic/app1/borgmatic.yaml ] && [ ! -d ${opt_app}/.nobackup ]); then
${BORGMATIC} -c /opt/borgmatic/app1/borgmatic.yaml;
fi
Add the following scripts in /etc/crontab
file. The cron job is scheduled to run a script every day at 4:15 AM, executed with root privileges. The output (both standard output and standard error) of the script is appended to the log file /tmp/borg-backup.log
.
1
2
# Run borgmatic backups
15 4 * * * root /usr/local/sbin/borg-all.sh >> /tmp/borg-backup.log 2>&1
This post is licensed under CC BY 4.0 by the author.