update backupscript

This commit is contained in:
Olaf Rempel 2010-04-17 14:49:41 +02:00
parent ed786ffcf1
commit 629dfa24ef

View File

@ -8,6 +8,8 @@ CONFIG="$1"
[ -f "$CONFIG" ] || exit 1
DATE="$(date +%Y-%m-%d)"
# $DATE must be the second field! (seperator=.)
BACKUP_PREFIX="$(hostname).$DATE"
umask 0077
@ -93,7 +95,7 @@ storage_put() {
calcold() {
filelist="$1"
keep="$2"
cut -d'.' -f2 $filelist > ${filelist}.dates
sed 's/.*\([[:digit:]]\{4\}-[[:digit:]]\{2\}-[[:digit:]]\{2\}\).*/\1/' $filelist > ${filelist}.dates
date -d "-${keep}" "+%Y-%m-%d-XXX" >> ${filelist}.dates
sort -r -u < ${filelist}.dates > ${filelist}.dates.uniq
@ -131,7 +133,7 @@ ftp) # ftp server
echo "REMOTE_STORAGE: ftp://${REMOTE_STORAGE_HOST}/${REMOTE_STORAGE_PATH} (keep $REMOTE_STORAGE_KEEP)" >&2
;;
ssh) # ssh / scp
ssh|scp)
[ -z "$REMOTE_STORAGE_PATH" ] && REMOTE_STORAGE_PATH="."
[ -n "$REMOTE_STORAGE_BANDWIDTH" ] && REMOTE_STORAGE_BANDWIDTH="-l $REMOTE_STORAGE_BANDWIDTH"
echo "REMOTE_STORAGE: ssh://${REMOTE_STORAGE_HOST}:${REMOTE_STORAGE_PATH} (keep $REMOTE_STORAGE_KEEP)" >&2
@ -183,9 +185,9 @@ for name in $BACKUPS; do
mysql_schema_dump="/usr/bin/mysqldump ${auth} --opt --all --no-data"
mysql_data_dump="/usr/bin/mysqldump ${auth} --opt --add-locks=FALSE --no-create-info"
created_mysql_files=""
if [ -z "$db_list" ]; then
db_list=$(echo "SHOW databases;" | $mysql_cmd)
fi
echo " privileges" >&2
sql="SELECT DISTINCT CONCAT(\"'\", user, \"'@'\", host, \"'\") FROM mysql.user ORDER BY user, host;"
@ -199,10 +201,10 @@ for name in $BACKUPS; do
done >> ${tmpdir}/privileges.sql
created_mysql_files="privileges.sql"
fi
for db in $db_list; do
echo " database $db" >&2
$mysql_schema_dump --databases $db > ${tmpdir}/${db}-schema.sql
$mysql_data_dump --databases $db > ${tmpdir}/${db}-data.sql
created_mysql_files="$created_mysql_files ${db}-schema.sql ${db}-data.sql"
@ -281,7 +283,8 @@ ftp) echo -e "\nremoving old (> $REMOTE_STORAGE_KEEP) backups from REMOTE_STORAG
done
;;
ssh) echo -e "\nremoving old (> $REMOTE_STORAGE_KEEP) backups from REMOTE_STORAGE" >&2
ssh|scp)
echo -e "\nremoving old (> $REMOTE_STORAGE_KEEP) backups from REMOTE_STORAGE" >&2
ssh $REMOTE_STORAGE_HOST "cd ${REMOTE_STORAGE_PATH}; ls -1 $(hostname).*" > ${tmpdir}/remote.files
remote_old_files=$(calcold ${tmpdir}/remote.files "$REMOTE_STORAGE_KEEP")