c01nd01r
3/31/2016 - 9:44 AM

yandex-webdav

#!/bin/sh
DB_USER="name"
DB_PASS="password"
DB_BASE="databese"
CLOUD_USER="webdav_user"
CLOUD_PASS="webdav_password"
MOUNTH=$(date +"%Y-%m")
CLOUD_SERVER="https://webdav.yandex.ru/"
NUM_WEEK=$(date +"%V")
NUM_DAY=$(date +"%u")
DUMP_FILE="${NUM_WEEK}-${NUM_DAY}.sql"
ZIP_PASS="zip_password"
ZIP_FILE=${DUMP_FILE}".zip"

mysqldump --opt --user=${DB_USER} --password=${DB_PASS}  ${DB_BASE} > ${DUMP_FILE}
echo "Mysql dump ${DUMP_FILE}\r";
zip --password ${ZIP_PASS} -j ${ZIP_FILE} ${DUMP_FILE}
echo "ZIP ${DUMP_FILE}\r";
rm ${DUMP_FILE}
echo "DELETE LOCAL ${DUMP_FILE}\r";
curl --user ${CLOUD_USER}:${CLOUD_PASS} -T ${ZIP_FILE} ${CLOUD_SERVER}
echo "SEND ${ZIP_FILE}\r";
rm ${ZIP_FILE}
echo "DELETE LOCAL ${ZIP_FILE}\r";
if [ ${NUM_DAY} -gt 1 ]; then
LAST_WEEK=$(date -d "-1 week" +"%V")
OLD_DUMP="${CLOUD_SERVER}${LAST_WEEK}-${NUM_DAY}.sql.zip"
curl --user ${CLOUD_USER}:${CLOUD_PASS} -X DELETE ${OLD_DUMP}
echo "DELETE ${OLD_DUMP}\r"
fi
if [ ${NUM_DAY} -eq 1 ]; then
LAST_MONTH=$(date -d "-4 week" +"%V")
OLD_DUMP="${CLOUD_SERVER}${LAST_MONTH}-${NUM_DAY}.sql.zip"
curl --user ${CLOUD_USER}:${CLOUD_PASS} -X DELETE ${OLD_DUMP}
echo "DELETE ${OLD_DUMP}\r"
fi