Quote:
Originally Posted by postmark
Would you mind sharing some examples? I'm working on a raspberry pi setup to auto backup photos across the Web and an kind of new to Linux backups :-)
|
Sure, here is one of the scripts I use:
Code:
date
sourcepath="/raid1/intranet/"
pathname="/raid1/backups/servers/borg/intranet/"
datefile=`date +%a`
mkdir -p ${pathname} > /dev/null
echo backing up...
rsync -vrbu --delete-during --delete-excluded ${sourcepath} ${pathname}cur
echo done
date
I tend to just reuse that and change the source/path. That's for local backups, non local I tend to just hard code as I go. Honestly, I've been wanting to just write a C++ app to automate all of this and generate the scripts based on a folder list I make. Maybe even make it web based.
This is one to backup one of my servers (runs off my main server)
Code:
dest="/data/backups/servers/hal9000/"
date
echo "Backing up HAL9000..."
mkdir -p ${dest}
rsync -rbuv --delete-after --delete-excluded "root@hal9000.loc:/data" "${dest}"
rsync -rbuv --delete-after --delete-excluded "root@hal9000.loc:/home" "${dest}"
rsync -rbuv --delete-after --delete-excluded "root@hal9000.loc:/etc" "${dest}"
echo Backup complete
date
The key though is setting up the key pair stuff so that you can ssh to remote servers without a password. I always forget how to do it off hand so I made a document on how to do it:
Quote:
How to configure rsync backups over key pair ssh
Server to backup to: srv_tx (pull data from srv_rx)
Server to backup: srv_rx
1: Generate key pair
On srv_tx:
Type ssh-keygen –t rsa [enter] and choose a location for the key pair
Basics:
File with no ext is specified by client to access server
.pub file is appended to server's /home/[user]/.ssh/authorized_keys
DO NOT enter a passphrasae
2: Distribute keys
On srv_rx in the user’s home directory create this file:
~/.ssh/authorized_keys
In it put the contents of the .pub key created in step 1 and make sure its chmodded 700 as well as the key files on srv_tx
Srv_tx now has passwordless access to srv_rx
Automated ssh access:
To execute a remote script on srv_rx from srv_tx:
ssh -p [port] –i [keyfile] [user]@srv_rx ‘cd dir;./runscript’
Automated Rsync backups:
To backup a dir of srv_rx to another dir on srv_tx:
rsync --delete-during --verbose --checksum --recursive --links --times --perms --rsh="ssh -p [port] -i [keyfile]” [user]@srv_rx:[remotedir] [backupdest]
To push backups, reverse:
[user]@srv_rx:[remotedir] [backupdest]
|
That's for "pull" backups but you can easily reverse it to do push as well. I personally prefer pull that way all my scripts are in a central location.
With the keypair setup you can also use ssh to run a remote command, such as mysqldump. So dump a db before running the rsync and then you backup databases too.