Skip to content

Simpleheberg/SimpleBackup-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SimpleBackup - Automatic Website & Database Backup Tool

Version Python License

SimpleBackup is a simple and reliable automatic backup tool for your websites and databases. Created by SimpleHeberg to simplify hosting backup management.

✨ Features

  • πŸ—‚οΈ 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

πŸ“‹ Requirements

  • Python 3.6 or higher
  • mysqldump for MySQL/MariaDB databases
  • pg_dump for PostgreSQL databases
  • Read permissions on folders to backup
  • Access to databases to backup

Installing Database Tools

Debian/Ubuntu:

# For MySQL/MariaDB
sudo apt-get install mysql-client

# For PostgreSQL
sudo apt-get install postgresql-client

CentOS/RHEL:

# For MySQL/MariaDB
sudo yum install mysql

# For PostgreSQL
sudo yum install postgresql

πŸš€ Installation

  1. Clone the repository:
git clone https://github.com/simpleheberg/simple-backup.git
cd simple-backup
  1. Make the script executable:
chmod +x backup_automator.py
  1. Create initial configuration:
./backup_automator.py --init

βš™οΈ Configuration

Edit 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
        }
    ]
}

Configuration Options

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

πŸ’‘ Usage

Manual Backup

# Use default configuration
./backup_automator.py

# Use custom configuration file
./backup_automator.py --config /path/to/config.json

Automation with Cron

To 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>&1

Frequency examples:

  • 0 2 * * * - Every day at 2:00 AM
  • 0 */6 * * * - Every 6 hours
  • 0 2 * * 0 - Every Sunday at 2:00 AM
  • 0 2 1 * * - 1st of each month at 2:00 AM

Weekly Full Backup

# Every Sunday at 3:00 AM
0 3 * * 0 /path/to/backup_automator.py --config /etc/backup/weekly_config.json

πŸ“ Backup Structure

Backups 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

File Naming Convention

  • Websites: {name}_website_{date}_{time}.tar.gz
  • MySQL/MariaDB: {name}_mysql_{date}_{time}.sql.gz
  • PostgreSQL: {name}_postgresql_{date}_{time}.sql.gz

πŸ” Security

Important Recommendations

  1. Protect your configuration file:
chmod 600 backup_config.json
  1. 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;
  1. Store backups outside the web server:
{
    "backup_dir": "/var/backups/sites",
    ...
}
  1. Encrypt sensitive backups:
# Example encryption with GPG
gpg --symmetric --cipher-algo AES256 backup.tar.gz

πŸ”§ Restoration

Restore a Website

# 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

Restore a MySQL Database

# Decompress and restore
gunzip < my_db_mysql_20240214_020030.sql.gz | mysql -u root -p my_prod_db

Restore a PostgreSQL Database

# Decompress and restore
gunzip < my_db_postgresql_20240214_020030.sql.gz | psql -U postgres my_prod_db

πŸ“Š Logs and Monitoring

Logs 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

πŸ› Troubleshooting

Issue: "mysqldump not found"

Solution:

# Install MySQL client
sudo apt-get install mysql-client  # Debian/Ubuntu
sudo yum install mysql             # CentOS/RHEL

Issue: "Access denied for user"

Solution: Check backup user permissions:

SHOW GRANTS FOR 'backup_user'@'localhost';

Issue: Backups too large

Solutions:

  • Exclude temporary files
  • Increase retention only for specific backups
  • Use external storage (NAS, S3, etc.)

Issue: Compression failure

Solution: Check available disk space:

df -h

🎯 Use Case Examples

WordPress

{
    "websites": [
        {
            "name": "wordpress_prod",
            "path": "/var/www/html/wordpress",
            "enabled": true
        }
    ],
    "databases": [
        {
            "name": "wordpress_db",
            "type": "mysql",
            "database": "wordpress",
            "enabled": true
        }
    ]
}

PrestaShop / WooCommerce

{
    "websites": [
        {
            "name": "shop",
            "path": "/var/www/html/prestashop",
            "enabled": true
        }
    ],
    "databases": [
        {
            "name": "shop_db",
            "type": "mysql",
            "database": "prestashop_prod",
            "enabled": true
        }
    ],
    "retention_days": 14
}

🀝 Contributing

Contributions are welcome! Feel free to:

  1. Fork the project
  2. Create a branch for your feature
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

🌐 About SimpleHeberg

SimpleBackup is developed and maintained by SimpleHeberg, your all-in-one web hosting solution.

Our Services

  • Professional web hosting
  • Website creation
  • Maintenance and technical support
  • Custom solutions

Need hosting? Contact us at simpleheberg.fr


Developed with ❀️ by SimpleHeberg | Website | Support

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages