Skip to main content
Losing data is a nightmare. With this simple bash script, you can create compressed archives of your important files and keep them organized.

The Script

Create a file called backup.sh: nano backup.sh Paste the following code:

How to Use It

  1. Save and Close: Press CTRL+O, Enter, then CTRL+X.
  2. Make the script executable: chmod +x backup.sh
  3. Run it manually: ./backup.sh

Automating with Cron (Scheduling)

You can have this script run automatically every day (e.g., at 4:00 AM).
  1. Open crontab: crontab -e
  2. Add this line to the end of the file: 0 4 * * * /path/to/your/backup.sh (Make sure to use the full path, e.g., /home/user/backup.sh)
  3. Save and close.
Now your server will automatically backup every night at 04:00 and automatically delete backups older than 7 days to avoid filling up the disk!
Guide created by HighMark - All information and contacts on my official website: Highmark.it