Created
March 26, 2009 04:15
-
-
Save tckz/85872 to your computer and use it in GitHub Desktop.
backup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
dir_backup_dst=/path/to/backup/`hostname` | |
timestamp=`date +%Y%m%d%H` | |
myname=`basename $0` | |
pid=$$ | |
( | |
if [ ! -d "$dir_backup_dst" ] | |
then | |
mkdir -p $dir_backup_dst | |
fi | |
myhost=`hostname -s` | |
while read host type need_clean name src | |
do | |
if [ -z "$name" ] | |
then | |
continue | |
fi | |
case "$host" in | |
\#*) | |
continue | |
;; | |
esac | |
if [ "$host" != "$myhost" ] && [ "$host" != "*" ] | |
then | |
echo "### Skip(type=$type) $name" 1>&2 | |
continue | |
fi | |
echo "### Archive(type=$type) $name" 1>&2 | |
arc="$dir_backup_dst/$timestamp-$name.$type" | |
/bin/rm -f $arc.gz $arc | |
case "$type" in | |
mysql) | |
# src means any option | |
mysqldump $name $src | grep -v "^-- Dump completed on" > $arc && gzip --no-name $arc | |
;; | |
pgsql) | |
# src means any option | |
pg_dump $src $name > $arc && gzip --no-name $arc | |
;; | |
tar) | |
tar cf $arc -C / `cd / && echo $src` | |
gzip --no-name $arc | |
;; | |
rsync) | |
rsync $src | |
;; | |
*) | |
echo "*** unknown type=$type" 1>&2 | |
;; | |
esac | |
if [ "$need_clean" = "0" ] | |
then | |
# rsyncの場合ローカルの整理がいらないので | |
continue | |
fi | |
ls -t "$dir_backup_dst"/*-$name.$type.gz | while read line | |
do | |
if [ "$line" = "$arc.gz" ] | |
then | |
continue | |
fi | |
diff -q $line $arc.gz > /dev/null 2>&1 | |
rc=$? | |
if [ $rc = 0 ] | |
then | |
echo "$name: Both previous archive and latest one are same." | |
/bin/rm -f $arc.gz | |
fi | |
break | |
done | |
done <<EOF | |
* tar 1 httpd-conf etc/httpd/conf/ etc/httpd/conf.local home/svn/authz | |
* tar 1 os-any etc/cron.daily/ etc/rc.local etc/samba/ etc/nsswitch.conf etc/hosts etc/group etc/sysconfig/ etc/passwd etc/logrotate.d/ etc/logrotate.conf etc/xinetd.d/ etc/ld.so.conf etc/ld.so.conf.d/ etc/krb5.conf etc/ssh/ etc/ntp.conf | |
* tar 1 os-perl usr/lib/perl5/site_perl | |
db pgsql 1 dbback -U user -h host | |
db rsync 0 sync2any -av /path/to/backup/ dst::rsync_name | |
EOF | |
echo "done." | |
) 2>&1 | logger -s -t "$myname[$pid]" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment