π€
Backup.Robot Use backup robot for regular backup schedules. Features:
- MySQL - backup MySQL/MariaDB databases. Supports multiple servers, one file per database. Automatically backups new databases, blacklist unwanted databases.
- Rsync - push local dirs to destination server. Supports copying SELinux attributes on target filesystems. Can be used for rsync "pull files" if orchestrated with installation on the backup server.
- Email report - the backup process can be configured to send a backup report to an email with custom subject for failed or success backups
Prerequisites
Install on a target server the following components:
- PHP (ex.
yum install php71w-cli php71w-xml php71w-bcmath php71w-mbstring
) - Composer (through system package manager or preferable via https://getcomposer.org/download/)
- MySQL client libraries for MySQL backup (
apt-get install mariadb-client
)
Setup
- Checkout this project on a target server (i.e.
git clone https://github.com/eaudeweb/backup.robot.git /opt/backup
) with a regular user account - Copy
robo.test.yml
torobo.yml
and restrict file permissions (i.e.chown root:root robo.yml && chmod 600 robo.yml
) - Customize configuration as stated in the next chapter.
- Run
composer install --no-dev
to setup the libraries - Start a backup using command:
./run.php backup:backup
- Install a CRON job (TODO) -
backup.sh
10 05 * * * root /opt/backup.robot/cron.sh 1>/dev/null 2>&1 || true
Disclaimer: The code above is not tested in production
Configuration
Configuration is done in robo.yml
file and is quite simple. You can define one or more backup projects (for simple deployments one project should be enough). A project consists of a set of actions per project.
For example dump databases, rsync everything to a target server then send me an email report. The configuration to do this is the following:
backup:
version: "1.0"
defaults:
timezone: 'Europe/Bucharest'
email:
enabled: true # Enable sending emails, globally
per-project: false; # Send emails for each backup project or only one global email with all tasks.
attachment-threshold: 3MB # If the log file is greater than this size it will be attached to email instead.
attachment-compress: true
server:
debug-level: 2 # 0 - no output (for production), 1 - client messages, 2 - client + server messages
type: smtp # or 'mail' or 'sendmail' or 'qmail'
host: mail.company.com
port: 465 # other ports: 25, 587
protocol: ssl # 'false' or 'ssl' (deprecated)
auth: true # use authentication
username: backup
password: secret
from: backup@company.com
to: destination.email@company.com
subject:
success: "[OK][SERVER-PROD01] Backup success"
fail: "[FAIL][SERVER-PROD01] Backup failed"
projects:
project1:
mysql:
server1:
host: silo1.company.com
port: 3306
user: root1
password: pass1
destination: /tmp/backup-robot-test/test/silo1/
gzip: true
blacklist: ["performance_schema", "information_schema", "db1"]
rsync:
mysql-dumps:
from: /tmp/backup-robot-test/test/databases/
to: /backups/PROJECT1/databases
user: bofh
host: backup-push-storage.company.com
port: 2279
Useful commands
backup:status
- Overview of backup tasks
$> ./run.php backup:status
β Backup rObOt v.0.0.1 - Crafted with β₯ at www.eaudeweb.ro
β ========== Backup summary ==========
β MySQL databases:
β - mara (root@127.0.0.1)
β - Connected successfully (mysqli loaded)
β - Backup to /home/cristiroma/work/infrastructure/backup.robot/data/PROJECT1/
β - Backup writable: YES
β - Backup databases: [holcim_eholcim, iucn_who, mysql, wildlex]
backup:backup
- Execute the actual backup according to configuration
$> ./run.php backup:backup
Development
Create a database test container:
docker run --name db -e MYSQL_ROOT_PASSWORD=root -d mariadb:latest --rm --expose="127.0.0.1:3306:3306"
Configure robo.yml with the details to connect to this container and backup the databases.