Backup Bot is an open-source software designed to automate daily backups of specified directories from multiple servers over SSH.
- Connect to multiple servers via SSH
- Create ZIP backups of specified folders
- Upload backups to S3-compatible storage
- Send email reports with backup status and errors
- Execute a command before backing up a server
- Support folders with blob in their names, e.g. /path/to/folder/my_*_data
- Support GFS (Grandfather-Father-Son) backup rotation
- Check server disk space or other metrics
- Check the backup integrity
- npm package @internet2000/backup-bot
- Docker image internet2000/backup-bot
- Node.js (version 14 or later)
- SSH access to the servers
- rsync installed on the servers
- S3-compatible storage (e.g., AWS S3, MinIO)
- Email SMTP server for sending reports
npx @internet2000/backup-bot
npm install -g @internet2000/backup-bot
-
Build the Docker image:
docker build -t backup-bot .
-
Run the Docker container:
docker run -v $(pwd)/config.yaml:/app/config.yaml backup-bot
Create a config.yaml
file in the root directory with the following structure:
strategy:
type: gfs # This will duplicate the backups for weekly, monthly, and yearly backups
servers:
- host: server1.example.com
user: username
backupCommand: "echo \"This command will run before backup\""
folders:
- /path/to/folder/ # Folders need a trailing slash
- /path/to/file.txt # Support files
- /path/to/all_*_folders/ # Support "*" in the file name or last folder only
- host: server2.example.com
user: username
folders:
- /path/to/folder3
s3:
endpoint: s3.example.com
bucket: your-bucket-name
access_key: your-access-key
secret_key: your-secret-key
email:
smtp_server: smtp.example.com
smtp_port: 587
username: your-email@example.com
password: your-email-password
to: recipient@example.com
Here are the available environment variables.
S3-compatible storage:
S3_ENDPOINT
: S3-compatible storage endpointS3_BUCKET
: S3 bucket nameS3_ACCESS_KEY_ID
: S3 access keyS3_SECRET_ACCESS_KEY
: S3 secret keyS3_REGION
: S3 region
Email:
SMTP_SERVER
: SMTP serverSMTP_PORT
: SMTP portSMTP_USERNAME
: SMTP usernameSMTP_PASSWORD
: SMTP passwordMAIL_FROM
: Email senderMAIL_TO
: Email recipientMAIL_DRY_RUN
: Dry run mode (true if exists)
Report:
REPORT_SUBJECT_SUCCESS
: Email subject for successful backupsREPORT_SUBJECT_ERROR
: Email subject for failed backupsREPORT_INCLUDE_FILE_TREE
: Include file tree in the email report, true if set to 'true', false by default
Used by the Docker image:
CONFIG_YAML
: Content of theconfig.yaml
file, see the Config file sectionSSH_PRIVATE_KEY
: SSH private keyCRONJOB
: Cron job schedule, e.g0 1 * * * /app/scripts/run.sh
You can check the server disk space or other metrics by adding the following configuration:
servers:
- host: server1.example.com
user: username
backupCommand: "df -h / | awk 'NR==2{if($5+0 > 75) exit 1}' || (>&2 echo \"Error: Hard drive is more than 3/4 full\" && exit 1)"
This will not backup anything since the folder
key is empty. The backupCommand
will run before the backup process. If the command returns a non-zero exit code, the report will include the error message.
npx @internet2000/backup-bot
backup-bot
docker run -v $(pwd)/config.yaml:/app/config.yaml @internet2000/backup-bot
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push (
git push origin main
) - Open a pull request