# Syncing servers



## nanotek (Jan 31, 2014)

Now that I've relocated one old box to another old but newer box. I would like to backup the new one to the old one on a daily basis. Essentially mirror the server, but I don't have zfs. What's the best way to do this over the LAN? net/rsync? How do I first setup the environment though? Do I need to first clone and restore the new box to the backup server and then implement rsync?


----------



## SirDice (Jan 31, 2014)

It depends a bit on what you want from the backups. A regular dump(8)/restore(8) will do but it'll be difficult to extract just a single file from it. Another option is to simply tar(1) stuff and store those. rsync can also be used to sync directories, the target directory doesn't need to have any files from it, the first run will copy everything, subsequent runs will only transfer the changes.


----------



## nanotek (Jan 31, 2014)

I want the backups in case of hardware failure or data corruption but also in the event of a broken system, so recovery, for lack of a better term. For example, it looks like my latest upgrade has rendered two systems all but unserviceable, so it would be nice to be able to "flash" an image to recover from such a scenario. Although something like the aforementioned situation, I'm hoping, is a rarity, a contingency plan seems prudent. Perhaps more importantly, I want a duplicate server ready to go live to provide at least email and cloud services with user data if the primary server breaks. In any event, I would like the process to be automated as much as possible. With that in mind, what do you suggest?


----------



## SirDice (Jan 31, 2014)

I would only backup the data and configuration files. It's usually faster installing a fresh FreeBSD compared to a restore(8). With a tar(1) or rsync it'll also be easier to restore a single file should it go missing or corrupt.


----------



## nanotek (Jan 31, 2014)

Thanks, @SirDice. Are there scripts that automate tar(1)? I don't particularly want to sit there and `tar` /usr/ and /root and send them across the LAN every evening. Would `rsync` be better at automating this process?


----------



## SirDice (Jan 31, 2014)

I usually create my own scripts to do this. Basically you set up a @backup user and allow it to `sudo tar` (so you can backup everything). The script contains a number of commands like this:
`ssh backup@server "sudo tar -C / -zcf - etc" > /storage/backups/server/etc-`date "+%Y%m%d"`.tgz`

Authentication is done using public/private key authentication and the script itself is run from @backup's crontab(1).


----------



## nanotek (Jan 31, 2014)

Nice! Thanks, @SirDice.


----------

