# 2006/12/04 authored by [email protected]
# Function for bac_serv.sh
# Local Host with Database
FuncDBlocal() {
[ -d $BAC_DIR ] || mkdir -p $BAC_DIR
cd $BAC_DIR
if [ `date +%w` = 6 ]; then
rm mysqldumpall-$HOST_NAME-`date –date="7 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="6 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="5 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="4 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="3 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="2 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="1 day ago" +%F`.sql.tar.gz
$DB_MYSQLDUMP -u $DB_USER -p$DB_PASS -A –opt > mysqldumpall-$HOST_NAME-`date +%F`.sql
tar zcvf mysqldumpall-$HOST_NAME-`date +%F`.sql.tar.gz mysqldumpall-$HOST_NAME-`date +%F`.sql
rm mysqldumpall-$HOST_NAME-`date +%F`.sql
else
if [ -f mysqldumpall-$HOST_NAME-`date +%F`.sql.tar.gz ]; then
:
else
$DB_MYSQLDUMP -u $DB_USER -p$DB_PASS -A –opt > mysqldumpall-$HOST_NAME-`date +%F`.sql
tar zcvf mysqldumpall-$HOST_NAME-`date +%F`.sql.tar.gz mysqldumpall-$HOST_NAME-`date +%F`.sql
rm mysqldumpall-$HOST_NAME-`date +%F`.sql
fi
fi
}
# Local Host with Files
FuncFILElocal() {
[ -d $BAC_DIR ] || mkdir -p $BAC_DIR
cd $BAC_DIR
if [ `date +%w` = 6 ]; then
echo "Today is 6"
echo "delete the past files"
rm file_$HOST_NAME-`date –date="7 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="6 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="5 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="4 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="3 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="2 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="1 day ago" +%F`.tar.gz
rm file_$HOST_NAME.snapshot
echo "restart bac"
tar zcvf file_$HOST_NAME-`date +%F`.tar.gz -g file_$HOST_NAME.snapshot $HOST_BK_DIR
else
if [ -f file_$HOST_NAME-`date +%F`.tar.gz ]; then
echo "Today is not 6"
echo "if the today file exists, and exits"
:
else
echo "every day incremential bac"
tar zcvf file_$HOST_NAME-`date +%F`.tar.gz -g file_$HOST_NAME.snapshot $HOST_BK_DIR
fi
fi
}
# Remote Host with Files
FuncFILE() {
[ -d $BAC_DIR ] || mkdir -p $BAC_DIR
echo "[ -d $BAC_DIR ] || mkdir -p $BAC_DIR" | ssh $LOGIN_NAME@$HOST_IP
if [ `date +%w` = 6 ]; then
echo "cd $BAC_DIR ; rm file_$HOST_NAME-`date –date="7 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm file_$HOST_NAME-`date –date="6 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm file_$HOST_NAME-`date –date="5 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm file_$HOST_NAME-`date –date="4 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm file_$HOST_NAME-`date –date="3 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm file_$HOST_NAME-`date –date="2 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm file_$HOST_NAME-`date –date="1 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm file_$HOST_NAME.snapshot" | ssh $LOGIN_NAME@$HOST_IP
cd $BAC_DIR
rm file_$HOST_NAME-`date –date="7 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="6 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="5 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="4 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="3 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="2 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="1 day ago" +%F`.tar.gz
echo "cd $BAC_DIR ; tar zcvf file_$HOST_NAME-`date +%F`.tar.gz -g file_$HOST_NAME.snapshot $HOST_BK_DIR" | ssh $LOGIN_NAME@$HOST_IP
scp -rp $LOGIN_NAME@$HOST_IP:$BAC_DIR/file_$HOST_NAME-`date +%F`.tar.gz $BAC_DIR
else
echo "cd $BAC_DIR ; [ -f file_$HOST_NAME-`date +%F`.tar.gz ]" | ssh $LOGIN_NAME@$HOST_IP
if [ $? = 0 ]; then
:
else
echo "cd $BAC_DIR ; tar zcvf file_$HOST_NAME-`date +%F`.tar.gz -g file_$HOST_NAME.snapshot $HOST_BK_DIR" | ssh $LOGIN_NAME@$HOST_IP
scp -rp $LOGIN_NAME@$HOST_IP:$BAC_DIR/file_$HOST_NAME-`date +%F`.tar.gz $BAC_DIR
fi
fi
}
# Remote Host with Database
FuncDB() {
[ -d $BAC_DIR ] || mkdir -p $BAC_DIR
echo "[ -d $BAC_DIR ] || mkdir -p $BAC_DIR" | ssh $LOGIN_NAME@$HOST_IP
if [ `date +%w` = 6 ]; then
echo "cd $BAC_DIR ; rm mysqldumpall-$HOST_NAME-`date –date="7 day ago" +%F`.sql.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm mysqldumpall-$HOST_NAME-`date –date="6 day ago" +%F`.sql.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm mysqldumpall-$HOST_NAME-`date –date="5 day ago" +%F`.sql.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm mysqldumpall-$HOST_NAME-`date –date="4 day ago" +%F`.sql.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm mysqldumpall-$HOST_NAME-`date –date="3 day ago" +%F`.sql.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm mysqldumpall-$HOST_NAME-`date –date="2 day ago" +%F`.sql.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm mysqldumpall-$HOST_NAME-`date –date="1 day ago" +%F`.sql.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
cd $BAC_DIR
rm mysqldumpall-$HOST_NAME-`date –date="7 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="6 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="5 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="4 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="3 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="2 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$HOST_NAME-`date –date="1 day ago" +%F`.sql.tar.gz
echo "cd $BAC_DIR ; $DB_MYSQLDUMP -u $DB_USER -p$DB_PASS -A –opt > mysqldumpall-$HOST_NAME-`date +%F`.sql" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; tar zcvf mysqldumpall-$HOST_NAME-`date +%F`.sql.tar.gz mysqldumpall-$HOST_NAME-`date +%F`.sql" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm mysqldumpall-$HOST_NAME-`date +%F`.sql" | ssh $LOGIN_NAME@$HOST_IP
scp -rp $LOGIN_NAME@$HOST_IP:$BAC_DIR/mysqldumpall-$HOST_NAME-`date +%F`.sql.tar.gz $BAC_DIR
else
echo "cd $BAC_DIR ; [ -f mysqldumpall-$HOST_NAME-`date +%F`.sql.tar.gz ]" | ssh $LOGIN_NAME@$HOST_IP
if [ $? = 0 ]; then
:
else
echo "cd $BAC_DIR ; $DB_MYSQLDUMP -u $DB_USER -p$DB_PASS -A –opt > mysqldumpall-$HOST_NAME-`date +%F`.sql" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; tar zcvf mysqldumpall-$HOST_NAME-`date +%F`.sql.tar.gz mysqldumpall-$HOST_NAME-`date +%F`.sql" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $BAC_DIR ; rm mysqldumpall-$HOST_NAME-`date +%F`.sql" | ssh $LOGIN_NAME@$HOST_IP
scp -rp $LOGIN_NAME@$HOST_IP:$BAC_DIR/mysqldumpall-$HOST_NAME-`date +%F`.sql.tar.gz $BAC_DIR
fi
fi
}
# Remote Windows Host with Files
FuncWIN() {
[ -d $BAC_DIR ] || mkdir -p $BAC_DIR
echo "[ -d $HOST_BAC_DIR ] || mkdir -p $HOST_BAC_DIR" | ssh $LOGIN_NAME@$HOST_IP
if [ `date +%w` = 6 ]; then
echo "cd $HOST_BAC_DIR ; rm file_$HOST_NAME-`date –date="7 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm file_$HOST_NAME-`date –date="6 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm file_$HOST_NAME-`date –date="5 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm file_$HOST_NAME-`date –date="4 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm file_$HOST_NAME-`date –date="3 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm file_$HOST_NAME-`date –date="2 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm file_$HOST_NAME-`date –date="1 day ago" +%F`.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm file_$HOST_NAME.snapshot" | ssh $LOGIN_NAME@$HOST_IP
cd $BAC_DIR
rm file_$HOST_NAME-`date –date="7 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="6 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="5 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="4 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="3 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="2 day ago" +%F`.tar.gz
rm file_$HOST_NAME-`date –date="1 day ago" +%F`.tar.gz
echo "cd $HOST_BAC_DIR ; tar zcvf file_$HOST_NAME-`date +%F`.tar.gz -g file_$HOST_NAME.snapshot $HOST_BK_DIR" | ssh $LOGIN_NAME@$HOST_IP
scp -rp $LOGIN_NAME@$HOST_IP:$HOST_BAC_DIR/file_$HOST_NAME-`date +%F`.tar.gz $BAC_DIR
else
echo "cd $HOST_BAC_DIR ; [ -f file_$HOST_NAME-`date +%F`.tar.gz ]" | ssh $LOGIN_NAME@$HOST_IP
if [ $? = 0 ]; then
:
else
echo "cd $HOST_BAC_DIR ; tar zcvf file_$HOST_NAME-`date +%F`.tar.gz -g file_$HOST_NAME.snapshot $HOST_BK_DIR" | ssh $LOGIN_NAME@$HOST_IP
scp -rp $LOGIN_NAME@$HOST_IP:$HOST_BAC_DIR/file_$HOST_NAME-`date +%F`.tar.gz $BAC_DIR
fi
fi
}
# Remote Windows Host with Oracle database
FuncORAintype() {
if [ $INTYPE = complete ]; then
EXPORT="$EXE $ORA_USER/$ORA_PASS@$ORA_NAME inctype=complete file=ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp"
else
EXPORT="$EXE $ORA_USER/$ORA_PASS@$ORA_NAME file=ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp"
fi
}
FuncORA() {
FuncORAintype
[ -d $BAC_DIR ] || mkdir -p $BAC_DIR
echo "[ -d $HOST_BAC_DIR ] || mkdir -p $HOST_BAC_DIR" | ssh $LOGIN_NAME@$HOST_IP
if [ `date +%w` = 6 ]; then
echo "cd $HOST_BAC_DIR ; rm ora-$HOST_NAME.$ORA_USER-`date –date="7 day ago" +%F`.dmp.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm ora-$HOST_NAME.$ORA_USER-`date –date="6 day ago" +%F`.dmp.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm ora-$HOST_NAME.$ORA_USER-`date –date="5 day ago" +%F`.dmp.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm ora-$HOST_NAME.$ORA_USER-`date –date="4 day ago" +%F`.dmp.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm ora-$HOST_NAME.$ORA_USER-`date –date="3 day ago" +%F`.dmp.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm ora-$HOST_NAME.$ORA_USER-`date –date="2 day ago" +%F`.dmp.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm ora-$HOST_NAME.$ORA_USER-`date –date="1 day ago" +%F`.dmp.tar.gz" | ssh $LOGIN_NAME@$HOST_IP
cd $BAC_DIR
rm ora-$HOST_NAME.$ORA_USER-`date –date="7 day ago" +%F`.dmp.tar.gz
rm ora-$HOST_NAME.$ORA_USER-`date –date="6 day ago" +%F`.dmp.tar.gz
rm ora-$HOST_NAME.$ORA_USER-`date –date="5 day ago" +%F`.dmp.tar.gz
rm ora-$HOST_NAME.$ORA_USER-`date –date="4 day ago" +%F`.dmp.tar.gz
rm ora-$HOST_NAME.$ORA_USER-`date –date="3 day ago" +%F`.dmp.tar.gz
rm ora-$HOST_NAME.$ORA_USER-`date –date="2 day ago" +%F`.dmp.tar.gz
rm ora-$HOST_NAME.$ORA_USER-`date –date="1 day ago" +%F`.dmp.tar.gz
echo "cd $HOST_BAC_DIR ; $EXPORT" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; tar zcvf ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp.tar.gz ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp" | ssh $LOGIN_NAME@$HOST_IP
scp -rp $LOGIN_NAME@$HOST_IP:$HOST_BAC_DIR/ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp.tar.gz $BAC_DIR
else
echo "cd $HOST_BAC_DIR ; [ -f ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp.tar.gz ]" | ssh $LOGIN_NAME@$HOST_IP
if [ $? = 0 ]; then
:
else
echo "cd $HOST_BAC_DIR ; $EXPORT" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; tar zcvf ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp.tar.gz ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp" | ssh $LOGIN_NAME@$HOST_IP
echo "cd $HOST_BAC_DIR ; rm ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp" | ssh $LOGIN_NAME@$HOST_IP
scp -rp $LOGIN_NAME@$HOST_IP:$HOST_BAC_DIR/ora-$HOST_NAME.$ORA_USER-`date +%F`.dmp.tar.gz $BAC_DIR
fi
fi
}
留言