| .gitignore | ||
| backup.sh | ||
| LICENSE | ||
| README.md | ||
| restore-backup.sh | ||
Freescout Backup and Restore Scripts
This repository contains scripts for backing up and restoring a Freescout installation, including both files and database. The scripts use Cloudflare R2 for storage and are designed to be run as cron jobs or manually as needed.
Prerequisites
- Bash
- MySQL client
- AWS CLI
pv(Pipe Viewer)- Access to a Freescout installation
- AWS S3 or Cloudflare R2 bucket
Mark both scripts as executable
chmod +x restore-backup.sh
chmod +x backup.sh
Environment Variables
Both scripts require the following environment variables to be set:
FREESCOUT_DIR: Directory of your Freescout installationDB_HOST: MySQL database hostDB_PORT: MySQL database portDB_USER: MySQL database userDB_PASS: MySQL database passwordDB_NAME: MySQL database nameR2_BUCKET: Name of your Cloudflare R2 bucketR2_ACCESS_KEY_ID: Cloudflare R2 access key IDR2_SECRET_ACCESS_KEY: Cloudflare R2 secret access keyR2_ENDPOINT: Cloudflare R2 endpoint URLTEMP_DIR: Temporary directory for storing backups
Backup Script (backup.sh)
This script creates backups of both the Freescout files and database, then uploads them to Cloudflare R2.
Features
- Creates compressed backups of Freescout files and database
- Uploads backups to Cloudflare R2
- Manages retention by keeping only the 5 most recent backups
- Uses
pvto show progress during backup creation and upload
Usage
- Set the required environment variables
- Run the script:
./backup.sh
Restore Script (restore.sh)
This script restores the latest backups of both Freescout files and database from Cloudflare R2.
Features
- Downloads the latest file and database backups from Cloudflare R2
- Restores files to the Freescout directory
- Imports the database backup into MySQL
Usage
- Set the required environment variables
- Run the script:
./restore-backup.sh
Setting Up as a Cron Job
To run the backup script automatically, you can set up a cron job. For example, to run the backup daily at 2 AM:
- Open the crontab file:
crontab -e
- Add the following line (adjust the path as needed):
0 2 /path/to/backup.sh > /path/to/backup.log 2>&1
Security Considerations
- Keep your environment variables secure and don't expose them in public repositories
- Ensure that only authorized users have access to these scripts and the backup storage
- Regularly test your backups by performing test restores
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.