A simple little script for automatic backup rotation.
In this example we create backups of the /var/mydata folder, archive them using gzip and tar, creating a file named mydata-date.tgz (for example, mydata-2011-08-06), and then delete all files older than 31 days.
#!/bin/sh
vDate=`date +"%Y-%m-%d"`
# Backing up
tar -czf /backups/mydata-${vDate}.tgz /var/mydata
# Rotating the logs, delete older than 31 days
find /backups/mydata-* -mtime +31 -exec rm {} \;
Accordingly, instead of /var/mydata - enter the path to the folder you need; instead of +31 - the number of days to keep backups; instead of mydata - the name for the backup files.
Comments