/kb

personal knowledgebase

Archive for the ‘backup’ tag

Importing a MySQL dump file

with one comment

mysql -h SERVER -uUSER -p DATABASE < DUMPFILE

Written by Håvard Grimelid

January 6th, 2009 at 7:58 pm

Posted in Server

Tagged with , ,

Backing up my Macbook with rsync, SSH and Cron

without comments

I’ve created a simple script which syncs my documents folder with a remote computer. The files are transferred across the SSH protocol and the backup is performed daily with assistance of cron.

My rsync script is very simple:

#!/bin/bash
rsync -avzr --delete-excluded --exclude="*.log" --exclude="*.aux" --exclude=".svn" --exclude=".classpath" --exclude=".cache" --exclude=".project" --exclude="*.class" --exclude="*.swp" --exclude=".DS_Store" --exclude=".metadata" -e "ssh -c blowfish" /Users/USERNAME/Documents USER@REMOTE_COMPUTER:REMOTE_DIRECTORY

It was quite tricky to set up the cron job until i realized that cron does know very little of the user’s system. The trick was to add SSH_AUTH_SOCK=/tmp/501/SSHKeychain.socket in front of the script refrence in crontab, so that it looks like:

55 21 * * * SSH_AUTH_SOCK=/tmp/501/SSHKeychain.socket /Users/USERNAME/etc/backup.sh

This will cause the backup script to run at 21:55 each night. For more info on cron, check out unixgeeks.org. Add the following at the end if you’d like to suppress the mail from cron: >& /dev/null.

Note that for this script to run, SSH has to be set up with keypairs authentication.

Written by Håvard Grimelid

September 13th, 2008 at 11:29 pm

Posted in Scripts,Server

Tagged with , , ,

Backup a MySQL database with mysqldump

without comments

It’s very easy, but I always have to look it up.

mysqldump --opt -u USERNAME -p -h HOST.HOST.COM DATABASE_TABLE > DUMPFILE.sql

Written by Håvard Grimelid

May 14th, 2008 at 6:29 pm

Posted in Server

Tagged with , , ,