This project is a Bash (/bin/sh) script written to automate the backup process for Minecraft (or any web service) files on a Linux server.
This script performs the critical DevOps practices of automated backup and disk space management. It minimizes the risk of data loss by removing the need for manual intervention.
- Automated Archiving: Compresses a specified source directory (
SOURCE_DIR) into.tar.gzformat. - Datestamping: Names each backup file with a clear timestamp (
world-YYYY-MM-DD.tar.gz) for easy identification. - Smart Cleanup: Automatically deletes backups older than a specified number of days (e.g., 7 days) to prevent disk space from filling up.
- Logging: Provides observability by writing all output (success or errors) to a
.logfile.
- Copy the
mcbackup.shscript to a directory on your server (e.g.,/volume1/scripts/). - Edit the settings section inside the script to match your system:
SOURCE_DIR="/your/server/files" BACKUP_DIR="/your/backup/location" DAYS_TO_KEEP=7
- Make the script executable:
chmod +x mcbackup.sh
This script is designed to be run automatically every day using a cronjob (scheduled task).
Add the following line using sudo crontab -e (example runs at 4:05 AM every morning):
5 4 * * * su - [YOUR_USERNAME] -c "/bin/sh /volume1/scripts/mcbackup.sh > /volume1/scripts/mcbackup.log 2>&1"