Ubuntu – Simple Backup Solution


I'm looking for a very basic backup script/package for a directory on my Ubuntu server. Currently I'm using a cronjob like this:

0 5 * * 1 sudo tar -Pzcf /var/backups/home.tgz /home/

But I want a solution which adds a timestamp to the filename and does not override old backups. Of course this will slowly flood my drive so old backups (e.g. older than 2 months) need to be deleted automatically.


UPDATE: I've decided to give the bounty to the logrotate-solution because of it's simplicity. But big thanks to all other answerers, too!

Best Answer

Simple solution using logrotate

If you want to keep it simple and without scripting, just stay with your current cronjob and in addition configure a logrotate rule for it.

To do that, place the following in a file named /etc/logrotate.d/backup-home:

/var/backups/home.tgz {
    rotate 8

From now on, each time logrotate runs (and it will normally do so every day at ~6:25am), it will check if it's suitable for rotation and, if so, rename your home.tgz to another file with a timestamp added. It will keep 8 copies of it, so you have roughly two months of history.

You can customize the timestamp using the dateformat option, see logrotate(8).

Because your backup job runs at 5am and logrotate runs at 6:25am you should make sure your tar backup runs well under 1h and 25m (I guess it will be much faster anyway).

Related Question