How to Set Up a Backup Script with tar
Introduction
Automated backups are essential for data safety. This guide shows you how to create a simple backup script using tar on your Linux VPS.
Step-by-step Guide
- Create a backup script file
- ano ~/backup.sh
- Add the following script (replace
/source/folderand/backup/folderas needed):- #!/bin/bash
- DATE=$(date +%F)
- tar -czvf /backup/folder/backup-$DATE.tar.gz /source/folder
- Save and close the file.
- Make the script executable
- chmod +x ~/backup.sh
- Run the script manually
- ~/backup.sh
- (Optional) Schedule daily backups with cron
- crontab -e
- Add this line to run the backup every day at 2 AM:n
- 0 2 * * * /home/youruser/backup.sh
Recommendations
- Store backups on a separate disk or remote server for extra safety.
- Regularly test your backups by restoring files.
- Clean up old backups to save space.
Call To Action
eed reliable storage for your backups? Check out our VPS plans: https://xernode.com/#pricing