mysqldb-backup.sh: add storage-cleanup
This commit is contained in:
parent
5a832e175a
commit
5b772ba11f
@ -10,6 +10,7 @@ SCP_PATH="backups/"
|
||||
STOR="/home/dbbackup/"
|
||||
STOR_USER="dbbackup:root"
|
||||
STOR_PERM="0600"
|
||||
STOR_DAYS="7"
|
||||
|
||||
# -------------
|
||||
|
||||
@ -19,21 +20,17 @@ DUMP_DATA="/usr/bin/mysqldump --opt --add-locks=FALSE --no-create-info"
|
||||
umask 0077
|
||||
NOW=`date +%Y-%m-%d-%H-%M`
|
||||
TMPDIR=`mktemp -d`
|
||||
TMPDIR2="$TMPDIR/$NOW"
|
||||
mkdir -p $TMPDIR2
|
||||
mkdir -p $TMPDIR/$NOW
|
||||
|
||||
# generate dumps
|
||||
db_list=`echo "show databases;" | /usr/bin/mysql -u${DB_USER} -p${DB_PASS} -r --column-name=FALSE`
|
||||
for db in $db_list; do
|
||||
$DUMP_SCHEMA -u${DB_USER} -p${DB_PASS} --databases $db > $TMPDIR2/$db-schema.sql
|
||||
$DUMP_DATA -u${DB_USER} -p${DB_PASS} $db > $TMPDIR2/$db-data.sql
|
||||
$DUMP_SCHEMA -u${DB_USER} -p${DB_PASS} --databases $db > $TMPDIR/$NOW/$db-schema.sql
|
||||
$DUMP_DATA -u${DB_USER} -p${DB_PASS} $db > $TMPDIR/$NOW/$db-data.sql
|
||||
done
|
||||
|
||||
# pack dumps together
|
||||
pushd . &> /dev/null
|
||||
cd $TMPDIR
|
||||
tar -czf database-$NOW.tar.gz $NOW
|
||||
popd &> /dev/null
|
||||
tar -czf database-$NOW.tar.gz -C $TMPDIR $NOW
|
||||
|
||||
# upload
|
||||
/usr/bin/scp -q $TMPDIR/database-$NOW.tar.gz ${SCP_USER}@${SCP_HOST}:${SCP_PATH}
|
||||
@ -43,4 +40,7 @@ chmod $STOR_PERM $TMPDIR/database-$NOW.tar.gz
|
||||
chown $STOR_USER $TMPDIR/database-$NOW.tar.gz
|
||||
mv $TMPDIR/database-$NOW.tar.gz $STOR
|
||||
|
||||
# delete old files in storage
|
||||
find $STOR -mtime $STOR_DAYS -exec rm {} \;
|
||||
|
||||
rm -rf $TMPDIR
|
||||
|
Loading…
Reference in New Issue
Block a user