Deleting old backups through the backup users account


#1

Currently my backup script can tar the Wordpress files/database in the normal user account, then it rsyncs it to the backup user account, then deletes the local copy on the normal server.

I’m doing this for three different websites, so the backups are being stored in the following structure (this is how it looks in the root folder of the backups, and the dashes mean subdirectories):

website1.com
-backup-2012-09-02-0000
–files_backup.2012-09-02-0000.tar
–mysql_backup.2012-09-02-0000.tar
-backup-2012-09-03-0000
–files_backup.2012-09-03-0000.tar
–mysql_backup.2012-09-03-0000.tar
website2.com
-backup-2012-09-02-0000
–files_backup.2012-09-02-0000.tar
–mysql_backup.2012-09-02-0000.tar
-backup-2012-09-03-0000
–files_backup.2012-09-03-0000.tar
–mysql_backup.2012-09-03-0000.tar
website3.com
-backup-2012-09-02-0000
–files_backup.2012-09-02-0000.tar
–mysql_backup.2012-09-02-0000.tar
-backup-2012-09-03-0000
–files_backup.2012-09-03-0000.tar
–mysql_backup.2012-09-03-0000.tar

Given the directory structure and the limited commands in rssh, ftp, sftp, or rsync, is it possible to write a bash script that can automatically delete all backups older than 30 days (or 14 days, or any other number)?

Thanks for the help.


#2

Write a batch file of sftp commands and call sftp.

http://www.mkssoftware.com/docs/man1/sftp.1.asp


#3

Alternatively, if you need to delete a directory, you can do that by rsyncing an empty directory onto it with the --delete flag set.