Connect to ForestRacks S3 Storage
Setup Rclone
Install Rclone:
apt install rclone
Configure Rclone:
Use this file as a base in .config/rclone/rclone.conf
, replacing username_here
with your username and password_here
with your password from the ForestRacks product portal:
.config/rclone/rclone.conf
[storage]
type = s3
provider = Minio
env_auth = false
access_key_id = username_here
secret_access_key = password_here
region = dal
endpoint = https://s3.forestracks.net
location_constraint =
server_side_encryption =
Create temporary directory:
mkdir -p /tmp/back/mysqldump /tmp/back/virtual
The following script is an example of how to backup example.txt from /root, all mysql databases, and all virtual machines. Make sure you replace bucket_name
with the name of your bucket:
backup.sh
#!/bin/bash
tmp_dir="/tmp/back"
node_id=$(echo "$(hostname)" | awk -F '.' '{print $1}')
# Backup /root/1.txt
rclone copy --dedupe-mode interleaved --bwlimit 60M "/root/1.txt" storage:bucket_name/files/${node_id}/$(date +%F)/
# Backup MySQL databases
if command -v mysqldump &> /dev/null; then
mysql -s -r -e 'show databases' | grep -vE '^(information_schema|performance_schema|mysql|sys)$' | while read db; do
mysqldump $db > "$tmp_dir/mysqldump/${db}.sql"
rclone copy --dedupe-mode interleaved --bwlimit 60M "$tmp_dir/mysqldump/${db}.sql" storage:bucket_name/mysqldump/${node_id}/$(date +%F)/
rm -f "$tmp_dir/mysqldump/${db}.sql"
done
fi
# Backup VMs using virsh
if command -v virsh &> /dev/null; then
virsh list | grep kvm | awk '{print $2}' | while read vm; do
dd if=/dev/yourvg/${vm}_img | gzip | dd of="$tmp_dir/virtual/${vm}_backup.gz" bs=4096 status=progress
rclone copy --dedupe-mode interleaved --bwlimit 60M "$tmp_dir/virtual/${vm}_backup.gz" storage:bucket_name/virtual/${node_id}/$(date +%F)/
rm -f "$tmp_dir/virtual/${vm}_backup.gz"
done
fi
Using Cronjobs
First install cron:
apt install cron
Add the cronjob:
(crontab -l ; echo "35 17 * * 1 /root/backup.sh")| crontab -