OS: Ubuntu 22.04 LTS
apt update && apt upgrade
apt install python3 python3-pip borgbackup htop net-tools mariadb-client
pip install --upgrade borgmatic
pip install --upgrade borgweb
generate-borgmatic-config
mkdir /etc/borgweb
touch /etc/borgweb/borgweb.conf
mkdir /root/backup-sources
mkdir /root/backup-sources/foobar.com
mkdir /root/backup-sources/foobar.com/www
mkdir /root/backup-sources/foobar.com/db
mkdir /root/backup-repository
mkdir /var/log/borg
borg init --encryption=repokey /root/backup-repository/
ssh-keygen
ssh-copy-id [email protected]
HOST = '0.0.0.0' # use 0.0.0.0 to bind to all interfaces
PORT = 5000 # ports < 1024 need root
DEBUG = False # if True, enable reloader and debugger
LOG_DIR = '/var/log/borg'
REPOSITORY = 'repo'
NAME = 'backup.log'
BACKUP_CMD = "echo Manual backup disabled"
# Where to look for files to backup, and where to store those backups.
# See https://borgbackup.readthedocs.io/en/stable/quickstart.html and
# https://borgbackup.readthedocs.io/en/stable/usage/create.html
# for details.
location:
source_directories:
- /root/backup-sources/foobar.com
repositories:
- /root/backup-repository
storage:
encryption_passphrase: "REDACTED"
retention:
keep_daily: 7
keep_weekly: 4
keep_monthly: 6
keep_yearly: 1
hooks:
before_backup:
- echo "Starting a backup."
before_prune:
- echo "Starting pruning."
before_compact:
- echo "Starting compaction."
before_check:
- echo "Starting checks."
before_extract:
- echo "Starting extracting."
after_backup:
- echo "Finished a backup."
after_compact:
- echo "Finished compaction."
after_prune:
- echo "Finished pruning."
after_check:
- echo "Finished checks."
after_extract:
- echo "Finished extracting."
on_error:
- echo "Error during prune/compact/create/check."
before_everything:
- echo "Starting actions."
- echo "Downloading files from ssh.foobar.hosting.ovh.net..."
- ssh [email protected] tar pczf - /homez.37/foobar/www | tar xzf - --no-same-owner -C /root/backup-sources/foobar.com/www/
- echo "Exporting mysql database foobar_foobar..."
- ssh mysqldump --no-tablespaces -u foobar_foobar -pREDACTED -h foobar-001.eu.clouddb.ovh.net -P 35233 foobar_foobar | gzip > /root/backup-sources/foobar.com/db/foobar_foobar.sql.gz
after_everything:
- echo "Completed actions."
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
#!/usr/bin/env bash
BORGWEB_CONFIG=/etc/borgweb/borgweb.conf /usr/local/bin/borgweb
/var/log/borg/*
{
rotate 12
monthly
compress
missingok
notifempty
}
0 2 * * * /usr/local/bin/borgmatic > /var/log/borg/backup-$(date '+\%Y-\%m-\%d').log 2>&1
service logrotate restart
chmod +x /etc/rc.local
systemctl enable rc-local
reboot