Skip to main content

Symlinks to backup servers

Let’s say you want to backup some files on a server, but not clone the whole thing. Here’s a way to do it that’s nice and easy to maintain over time.

  1. Create a folder. This will be the directory we back up.

    mkdir /to-backup.

  2. Symlink everything you want to backup into that folder.

    For example, to backup your nginx config, you could do ln -s /etc/nginx /to-backup.

  3. Use rsync in a cron job or similar to regularly copy that folder to another machine. Use the -L flag so the symlinks are followed.

    For example, on a remote machine, you could run rsync -azL --delete [email protected]:/to-backup /backup-destination. You could also use rrsync to make a restricted user account for this backup job.

That’s it! Now you can add something to your backup jobs just by symlinking it into your backup directory.

Of course, it’s probably still worth doing a full clone of the server periodically to speed up recovery after a big failure, but this is nice for key files and config.

Next post:

Previous post: