DUMP=`date +"%Y%m%d_%H%M%S"`
echo begin dump $DUMP
TARGET=/opt/db/backup
if [ -e /tmp/.backup.run ];then
echo backup running.skip this
exit 3;
fi
touch /tmp/.backup.run
mysqldump -u root --databases auth idc usercenter res proddb | gzip - > $TARGET/51idc-$DUMP.sql.gz
mysqldump -u root --databases rich | gzip - > $TARGET/icp-$DUMP.sql.gz
rm /tmp/.backup.run
echo BACKUP 51idc-$DUMP.sql.gz
echo BACKUP icp-$DUMP.sql.gz
#clear files before two month
echo delete files before 10 days ago
find $TARGET/ -name "51idc-*" -mtime +10 -print -delete
find $TARGET/ -name "icp-*" -mtime +10 -print -delete
find $TARGET/ -name "fetch-*" -mtime +10 -print -delete
echo finished `date +"%Y%m%d_%H%M%S"`