Обсуждение статьи тематического каталога: Скpипт для полных и инкpементальных бэкапов (backup script example)Ссылка на текст статьи: http://www.opennet.me/base/sys/backup_sh.txt.html
А я таким под линухом пользуюсь:#!/bin/sh
# Dump file systems in Towers of Hanoi order. Store level 1 dumps forever.
# Full level 0 dumps are done if file num is lost.cd /mnt/old/home
num=`/bin/cat /mnt/old/home/num`
case $num in
0) num=3; fn1=$num;;
1) num=3; fn1=$num;;
3) num=2; fn1=$num;;
2) num=5; fn1=$num;;
5) num=4; fn1=$num;;
4) num=7; fn1=$num;;
7) num=6; fn1=$num;;
6) num=9; fn1=$num;;
9) num=8; fn1=$num;;
8) num=1; fn1=`date '+1-%Y%m%d'`;;
# start from level 0 if last level is lost
*) num=0; fn1=`date '+0-%Y%m%d'`;;
esac
for fs in "" var usr home ; do
fsn=$fs
if [ "${fs}X" == "X" ]; then fsn="root"; fi
echo ${fsn}:
nice /sbin/dump -${num}u -f - /${fs} | nice /bin/gzip - | split -b 2000m - ${fsn}.${fn1}.dump.gz.
chown user ${fsn}.${fn1}.dump.gz*
done
echo $num > num
Я немного переделал скрипт под себя, использую под FreeBSD - убрал split, немного упростил выборку из списка директорий, добавил флаги для получения Live snapshot при дампе. Получилось вот такое:#!/bin/sh
# Dump file systems in Towers of Hanoi order. Store level 1 dumps forever.
# Full level 0 dumps are done if file num is lost.
cd /snap
num=`/bin/cat /snap/num`
case $num in
0) num=3; fn1=$num;;
1) num=3; fn1=$num;;
3) num=2; fn1=$num;;
2) num=5; fn1=$num;;
5) num=4; fn1=$num;;
4) num=7; fn1=$num;;
7) num=6; fn1=$num;;
6) num=9; fn1=$num;;
9) num=8; fn1=$num;;
8) num=1; fn1=`/bin/date '+1-%Y%m%d'`;;
# start from level 0 if last level is lost
*) num=0; fn1=`/bin/date '+0-%Y%m%d'`;;
esac
for fs in / /var /usr /home ; do
nice /sbin/dump -${num}Luan -f - ${fs} | nice /usr/bin/gzip -2 | /bin/dd of=${fs}.${fn1}.dump.gz.
chown root ${fs}.${fn1}.dump.gz*
done
echo $num > num
cd -
Ну приложу я здесь и свою скриптявину ... а то потеряю ещё :)#!/bin/sh
work_dir="/samba/films/backup/files"
tmp_dir="/samba/films/backup/tmpdir"
backup_list="/samba/films/backup/list"
full_dir="/samba/films/backup/full_dir"[ ! -d $work_dir ] && mkdir $work_dir
[ ! -d $tmp_dir ] && mkdir $tmp_dir
[ ! -d $backup_list ] && touch $backup_list
[ ! -d $full_dir ] && touch $full_dirif ([ -f $work_dir/backup-$(date +%Y%m%d)-select.tar.gz ]);
then
echo "File exists. Moving file *select.tar.gz*..."
mv $work_dir/backup-$(date +%Y%m%d)-select.tar.gz $tmp_dir/backup-old-$(date +%Y%m%d)-select.tar.gz
fi
if ([ -f $work_dir/backup-$(date +%Y%m%d)-bases_sql.tar.gz ]);
then
echo "File exists. Moving file *bases_sql.tar.gz*..."
mv $work_dir/backup-$(date +%Y%m%d)-bases_sql.tar.gz $tmp_dir/backup-old-$(date +%Y%m%d)-bases_sql.tar.gz
fiif ([ -f $work_dir/backup-$(date +%Y%m%d)-full_dir.tar.gz ]);
then
echo "File exists. Moving file *full_dir.tar.gz*..."
mv $work_dir/backup-$(date +%Y%m%d)-full_dir.tar.gz $tmp_dir/backup-old-$(date +%Y%m%d)-full_dir.tar.gz
fi
/usr/local/bin/mysqldump --password=password --all-databases > $work_dir/bases.sql
find /etc/namedb/ -name "*.ru" > /samba/films/backup/list
find /etc/ -name "rc.*" >> /samba/films/backup/list
find /usr/ -name "*.conf" >> /samba/films/backup/list
find /etc/ -name "*.conf" >> /samba/films/backup/list
find /etc/ -name "aliases" >> /samba/films/backup/list
#echo "cobctevenno cam backup"
tar -czf $work_dir/backup-$(date +%Y%m%d)-select.tar.gz `cat $backup_list` 2>&1 | grep -v "Removing leading"
tar -czf $work_dir/backup-$(date +%Y%m%d)-bases_sql.tar.gz $work_dir/bases.sql 2>&1 | grep -v "Removing leading"
tar -czf $work_dir/backup-$(date +%Y%m%d)-full_dir.tar.gz `cat $full_dir` 2>&1 | grep -v "Removing leading" | grep -v "socket ignored"
rm -rf $work_dir/bases.sql
#cmd=`basename $0`
#optfiles="Usage: $cmd"
echo "Congratulations, done backup files"