A forum which I admin (and recently upgraded to phpBB 3.0.0 — which I adore) needed a fairly robust backup solution. So, I set up a couple of simple shell scripts to dump the database, tar/gzip the filestructure and database file, and move those archives to a separate directory structure for backups on a second harddrive.
However, the issue remains that if something happens to that machine, somehow zapping both harddrives, we would be fucked. So, I needed a way to get those backups from the server and onto my machine on a nightly basis. Initially I wrote a little PHP script to make use of the FTP functions and just get things that way. FTP turned out to be disabled on the server, which led me to use the more-secure SCP. As SCP doesn’t have a way to pass the password within the command, I needed a way to run the command, then provide a password, then wait for it to trasnfer the files I wanted. Enter, expect.
Expect provides a way to run a command and interact with it as if you were at the keyboard. It is pretty nifty, and I ended up using the script below to SCP relevant archives onto my machine on a nightly basis. All automated scheduling thanks to cron of course.
#!/usr/bin/expect —
set timeout 1200
set USER “username”
set PASS “p4ssw0rd”
set HOST “host.name.com”
set REMOTEPATH “/home/username/location/of/files”
set LOCALPATH “/home/othername/place/to/put/files”spawn scp $USER@$HOST:$REMOTEPATH/*.tar.gz $LOCALPATH
expect “Password:”
send — $PASS\r
expect eof
1 comment so far ↓
pfft, I’d just Run a cron job of rsync, gzip and mcrypt piped over ssh and that would be that
Leave a Comment