Stupid-Silly Back-up Script 2 comments

Posted by robon November 21, 2007

Went looking for this script again just now. I’m putting here as an entry for faster reference. Nothing ground-breaking here, just a stupid-silly back-up script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cardero:~/bin pmcweb$ cat backup-pmc-site.sh 
#!/bin/sh

BACKUP_BASE=/users/home/pmcweb/backups
BACKUP_DIR=$BACKUP_BASE/pmcweb_`date +%m-%d-%Y`

if [ ! -e $BACKUP_DIR ]; then
    echo "making back-up directory:"
    echo "$BACKUP_DIR"
    /bin/mkdir $BACKUP_DIR
    echo "dumping database..."
    /usr/bin/mysqldump prn -u USER -P PASSWORD > $BACKUP_DIR/db-dump_`date +%m-%d-%Y`.sql
fi

# nuke back-ups older then 5 days:
find $BACKUP_BASE/pmcweb_* -ctime +5 -maxdepth 0 -print | xargs rm -rf

Jackson's Bed 1 comment

Posted by robon November 15, 2007


No more init scripts?? Cool. 2 comments

Posted by robon November 15, 2007

I don’t know why this took so long for me to find out about crontab “nicknames” but I figure if it’s news to me, then it may be to many others too.

You need a service to restart with your server. You’ve done this enough that you’re eyes roll when you `cd` into /etc/rc.d or whatever, to create and initialization script for your service. Init scripts are pretty damn handy to have around for whatever services you have. They provide a standardized way to stop, start, and restart your service.

Unfortunately, writing init scripts is a pain in the ass. Ancient Unix Rule: Anything that’s a pain in the ass will get put on the back burner in the near future. For now, you just want to make sure your damn service starts when the idiot down at the colo power cycles your rack.

Quick, use cron:

1
2
-bash-3.00# crontab -l
@reboot cd /var/www/RAILS-APP/current; rm tmp/pids/mongrel.*.pid; mongrel_rails cluster::start

Done! Now either get back to work, or post a comment about your experience with restarting services and why this may or may not help you.

Here are more of these handy crontab short-cuts (from `man 5 crontab`):

These  special  time  specification  "nicknames"  are supported, which replace the 
5 initial time and date fields, and are prefixed by the '@' character:
@reboot    :    Run once, at startup.
@yearly    :    Run once a year, ie.  "0 0 1 1 *".
@annually  :    Run once a year, ie.  "0 0 1 1 *".
@monthly   :    Run once a month, ie. "0 0 1 * *".
@weekly    :    Run once a week, ie.  "0 0 * * 0".
@daily     :    Run once a day, ie.   "0 0 * * *".
@hourly    :    Run once an hour, ie. "0 * * * *".