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.
- Bash
- MySQL client
- AWS CLI
pv
(Pipe Viewer)- Access to a Freescout installation
- AWS S3 or Cloudflare R2 bucket
chmod +x restore-backup.sh
chmod +x backup.sh
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
This script creates backups of both the Freescout files and database, then uploads them to Cloudflare R2.
- Creates compressed backups of Freescout files and database
- Uploads backups to Cloudflare R2
- Manages retention by keeping only the 5 most recent backups
- Uses
pv
to show progress during backup creation and upload
- Set the required environment variables
- Run the script:
./backup.sh
This script restores the latest backups of both Freescout files and database from Cloudflare R2.
- Downloads the latest file and database backups from Cloudflare R2
- Restores files to the Freescout directory
- Imports the database backup into MySQL
- Set the required environment variables
- Run the script:
./restore-backup.sh
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
- 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
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.