SimpleBackup is a simple and reliable automatic backup tool for your websites and databases. Created by SimpleHeberg to simplify hosting backup management.
- ποΈ Website Backup: Complete archiving of your files
- ποΈ Database Backup: MySQL/MariaDB and PostgreSQL support
- ποΈ Automatic Compression: Files compressed in .tar.gz to save space
- π Backup Rotation: Automatic deletion of old backups
- π Detailed Logs: Complete tracking of each operation
- βοΈ JSON Configuration: Simple and readable settings
- π Automation: Easy to integrate with cron
- Python 3.6 or higher
mysqldumpfor MySQL/MariaDB databasespg_dumpfor PostgreSQL databases- Read permissions on folders to backup
- Access to databases to backup
Debian/Ubuntu:
# For MySQL/MariaDB
sudo apt-get install mysql-client
# For PostgreSQL
sudo apt-get install postgresql-clientCentOS/RHEL:
# For MySQL/MariaDB
sudo yum install mysql
# For PostgreSQL
sudo yum install postgresql- Clone the repository:
git clone https://github.com/simpleheberg/simple-backup.git
cd simple-backup- Make the script executable:
chmod +x backup_automator.py- Create initial configuration:
./backup_automator.py --initEdit the automatically created backup_config.json file:
{
"backup_dir": "./backups",
"retention_days": 7,
"compression": "gz",
"websites": [
{
"name": "my_site",
"path": "/var/www/html/mysite",
"enabled": true
}
],
"databases": [
{
"name": "my_database",
"type": "mysql",
"host": "localhost",
"port": 3306,
"user": "backup_user",
"password": "secure_password",
"database": "my_prod_db",
"enabled": true
}
]
}| Option | Description | Default Value |
|---|---|---|
backup_dir |
Backup destination folder | ./backups |
retention_days |
Number of days to keep backups | 7 |
compression |
Compression type | gz |
websites[].enabled |
Enable/disable backup | false |
databases[].type |
Database type: mysql, mariadb, postgresql |
- |
databases[].enabled |
Enable/disable backup | false |
# Use default configuration
./backup_automator.py
# Use custom configuration file
./backup_automator.py --config /path/to/config.jsonTo run automatic daily backups at 2 AM:
# Edit crontab
crontab -e
# Add this line (adjust path)
0 2 * * * /path/to/backup_automator.py >> /var/log/backup.log 2>&1Frequency examples:
0 2 * * *- Every day at 2:00 AM0 */6 * * *- Every 6 hours0 2 * * 0- Every Sunday at 2:00 AM0 2 1 * *- 1st of each month at 2:00 AM
# Every Sunday at 3:00 AM
0 3 * * 0 /path/to/backup_automator.py --config /etc/backup/weekly_config.jsonBackups are organized as follows:
backups/
βββ logs/
β βββ backup_20240214.log
βββ my_site_website_20240214_020000.tar.gz
βββ my_db_mysql_20240214_020030.sql.gz
βββ other_site_website_20240214_020100.tar.gz
- Websites:
{name}_website_{date}_{time}.tar.gz - MySQL/MariaDB:
{name}_mysql_{date}_{time}.sql.gz - PostgreSQL:
{name}_postgresql_{date}_{time}.sql.gz
- Protect your configuration file:
chmod 600 backup_config.json- Create a dedicated backup user:
MySQL:
CREATE USER 'backup_user'@'localhost' IDENTIFIED BY 'strong_password';
GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON *.* TO 'backup_user'@'localhost';
FLUSH PRIVILEGES;PostgreSQL:
CREATE USER backup_user WITH PASSWORD 'strong_password';
GRANT CONNECT ON DATABASE my_db TO backup_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO backup_user;- Store backups outside the web server:
{
"backup_dir": "/var/backups/sites",
...
}- Encrypt sensitive backups:
# Example encryption with GPG
gpg --symmetric --cipher-algo AES256 backup.tar.gz# Extract the archive
tar -xzf my_site_website_20240214_020000.tar.gz -C /var/www/html/
# Check permissions
chown -R www-data:www-data /var/www/html/my_site# Decompress and restore
gunzip < my_db_mysql_20240214_020030.sql.gz | mysql -u root -p my_prod_db# Decompress and restore
gunzip < my_db_postgresql_20240214_020030.sql.gz | psql -U postgres my_prod_dbLogs are stored in backups/logs/ with one file per day:
[2024-02-14 02:00:00] - INFO - Starting backup process...
[2024-02-14 02:00:05] - INFO - Backing up website: my_site
[2024-02-14 02:00:12] - INFO - β Website backup completed: my_site_website_20240214_020000.tar.gz (45.32 MB)
[2024-02-14 02:00:15] - INFO - Backing up MySQL database: my_prod_db
[2024-02-14 02:00:28] - INFO - β MySQL backup completed: my_db_mysql_20240214_020015.sql.gz (12.45 MB)
[2024-02-14 02:00:30] - INFO - Cleaning up backups older than 7 days...
[2024-02-14 02:00:31] - INFO - β Cleaned up 3 old backup(s), freed 123.45 MB
[2024-02-14 02:00:31] - INFO - Backup process completed: 2 successful, 0 failed
Solution:
# Install MySQL client
sudo apt-get install mysql-client # Debian/Ubuntu
sudo yum install mysql # CentOS/RHELSolution: Check backup user permissions:
SHOW GRANTS FOR 'backup_user'@'localhost';Solutions:
- Exclude temporary files
- Increase retention only for specific backups
- Use external storage (NAS, S3, etc.)
Solution: Check available disk space:
df -h{
"websites": [
{
"name": "wordpress_prod",
"path": "/var/www/html/wordpress",
"enabled": true
}
],
"databases": [
{
"name": "wordpress_db",
"type": "mysql",
"database": "wordpress",
"enabled": true
}
]
}{
"websites": [
{
"name": "shop",
"path": "/var/www/html/prestashop",
"enabled": true
}
],
"databases": [
{
"name": "shop_db",
"type": "mysql",
"database": "prestashop_prod",
"enabled": true
}
],
"retention_days": 14
}Contributions are welcome! Feel free to:
- Fork the project
- Create a branch for your feature
- Commit your changes
- Push to the branch
- Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
SimpleBackup is developed and maintained by SimpleHeberg, your all-in-one web hosting solution.
- Professional web hosting
- Website creation
- Maintenance and technical support
- Custom solutions
Need hosting? Contact us at simpleheberg.fr