This project provides robust, secure scripts for automated server data backups using FTP with encryption and retention management.
-
Secure Backup:
- Encrypted database and file backups
- Supports multiple directories
- Secure FTP transfer
-
Automated Management:
- Automatic backup scheduling
- Retention of last 8 backups
- Old backups automatically pruned
-
Easy Configuration:
- Single
.env
file for all sensitive configurations - Strict file permission recommendations
- Single
bash
lftp
gpg
mysql
(for database backups)
Create a .env
file with the following structure:
# FTP Credentials
FTP_HOST="your-ftp-host"
FTP_USER="your-ftp-username"
FTP_PASS="your-ftp-password"
# Backup Configuration
BACKUP_DIRS=("/path/to/directory1" "/path/to/directory2")
BACKUP_RETENTION_COUNT=8
# Database Configuration
DB_HOST="localhost"
DB_USER="root"
DB_PASS="your-root-password"
DB_NAME="your-database-name"
# Security
ENCRYPTION_PASSPHRASE="strong-unique-passphrase"
# Secure .env file
chmod 600 .env
# Make scripts executable
chmod 700 backup_to_ftp.sh restore_from_ftp.sh
./backup_to_ftp.sh
./restore_from_ftp.sh
Edit crontab to schedule daily backups:
crontab -e
Add the following line (adjusts time as needed):
0 2 * * * /path/to/backup_to_ftp.sh
- Use strong, unique passphrases
- Regularly rotate encryption keys
- Monitor backup logs
- Test restore procedures periodically
- Store
.env
file securely - Use firewall and network restrictions
- Check system logs for detailed error information
- Verify FTP and database credentials
- Ensure all dependencies are installed
- Confirm network connectivity
Contributions welcome! Please submit pull requests or open issues for improvements.