## date format ##
NOW=$(date +"%F")
NOWT=$(date +"%T")
## Backup path ##
BAK="/nfs/backup/mysql/$NOW"
## Login info ##
MUSER="madmin"
MPASS="PASSWORD"
MHOST="127.0.0.1"
## Binary path ##
MYSQL="/usr/bin/mysql"
MYSQLDUMP="/usr/bin/mysqldump"
GZIP="/bin/gzip"
## Get database list ##
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
## Use shell loop to backup each db ##
for db in $DBS
do
FILE="$BAK/mysql-$db-$NOWT.gz"
echo "$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE"
done
echo 'yes abcd' | ssh --stdin user25@192.168.1.1
===================================================================
Delete files based on date
#!/bin/bash
Path=/tmp
d=$(date +%d --date="1 days ago")
file=$(ls -lh $Path | awk '{print $6 " " $7 " " $9}' | sed -n /$d/p)
count=`echo -n "$file" | wc -l`
if [ 0 == "$count" ];then
echo "date is not Match with file"
else
echo "date is Match with file"
fi
No comments:
Post a Comment