How do I set up a cron job to automate backups on a VPS?
Asked on Oct 27, 2025
Answer
To set up a cron job for automating backups on a VPS, you'll need to define a schedule and specify the backup command in the crontab file. This allows you to run scripts or commands at regular intervals.
# Open the crontab editor
crontab -e
# Add the following line to schedule a daily backup at 2 AM
0 2 * * * /usr/bin/backup-script.sh
Additional Comment:
- Ensure the backup script "/usr/bin/backup-script.sh" is executable and correctly configured to perform the desired backup tasks.
- Use absolute paths in your script to avoid path issues during execution.
- Test your backup script manually before scheduling it with cron to ensure it works as expected.
- Consider logging the output of your cron job to a file for troubleshooting purposes.
- Adjust the cron timing as needed to fit your backup schedule requirements.
Recommended Links: