- Copy all of those files in
/opt/dump
- Configure config.cfg
- Cron your dump for dumpfiles.sh and dumpsql.sh
Last active
August 29, 2015 13:57
-
-
Save cedriclombardot/9599355 to your computer and use it in GitHub Desktop.
Shells de sauvegarde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DUMPDIR="/opt/dump/data" | |
# SQL | |
SQLDUMPDIR="${DUMPDIR}/sql" | |
SQLUSER="root" | |
SQLPASS="password" | |
SQLKEEPDAYS="+3" | |
SQLDB=("DB1" "DB1") | |
# FILES | |
FILESDUMPDIR="${DUMPDIR}/files" | |
FILESKEEPDAYS="+3" | |
FOLDERSTODUMP=("ZIP_NAME:/home/a_directory_to_save") | |
# FTP | |
FTPHOST="xxx.ovh.net" | |
FTPLOGIN="login" | |
FTPPASS="passe" | |
FTPSQLDIR="sql" | |
FTPFILESDIR="files" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
. ./config.cfg | |
ftp -v -n $FTPHOST <<FTP_END | |
user $FTPLOGIN $FTPPASS | |
cd $1 | |
del $2 | |
quit | |
FTP_END | |
echo "Ftp file $2 removed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DATEFILENAME=`date +%Y-%m-%d_%H-%M` | |
SCRIPTDIR=`pwd` | |
. /opt/dump/config.cfg | |
. /opt/dump/uploadFtpFile.sh | |
# Create folders | |
mkdir -p $DUMPDIR | |
mkdir -p $FILESDUMPDIR | |
####################################### | |
#### DUMP FILES ############ | |
####################################### | |
for FOLDER in "${FOLDERSTODUMP[@]}" | |
do | |
TAR_NAME="${DATEFILENAME}_${FOLDER%%:*}.tar.gz" | |
FOLDER=${FOLDER#*:} | |
tar -zcvf "${FILESDUMPDIR}/${TAR_NAME}" ${FOLDER} | |
# Upload | |
cd $FILESDUMPDIR | |
uploadFtpFile $FTPFILESDIR $TAR_NAME | |
# Clean old | |
cd $FILESDUMPDIR | |
find -type f -ctime $FILESKEEPDAYS | cut -d / -f2 | xargs -I {} sh ${SCRIPTDIR}/delFtpFile.sh $FTPFILESDIR {} | |
find -type f -ctime $FILESKEEPDAYS | cut -d / -f2 | xargs -I {} rm {} | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DATEFILENAME=`date +%Y-%m-%d_%H-%M` | |
SCRIPTDIR=`pwd` | |
. /opt/dump/config.cfg | |
. /opt/dump/uploadFtpFile.sh | |
# Create folders | |
mkdir -p $DUMPDIR | |
mkdir -p $SQLDUMPDIR | |
####################################### | |
#### DUMP SQL ############## | |
####################################### | |
for DB in "${SQLDB[@]}" | |
do | |
SQLDUMPNAME="${DATEFILENAME}_${DB}.sql" | |
mysqldump -u $SQLUSER -p$SQLPASS $DB > "${SQLDUMPDIR}/${SQLDUMPNAME}" | |
# Upload to ftp | |
cd $SQLDUMPDIR | |
uploadFtpFile $FTPSQLDIR $SQLDUMPNAME | |
# Clean old | |
cd $SQLDUMPDIR | |
find -type f -ctime $SQLKEEPDAYS | cut -d / -f2 | xargs -I {} sh ${SCRIPTDIR}/delFtpFile.sh $FTPSQLDIR {} | |
find -type f -ctime $SQLKEEPDAYS | cut -d / -f2 | xargs -I {} rm {} | |
done | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
####################################### | |
#### FTP UPLOAD ############## | |
####################################### | |
uploadFtpFile() | |
{ | |
ftp -v -n $FTPHOST <<FTP_END | |
user $FTPLOGIN $FTPPASS | |
mkdir $1 | |
cd $1 | |
send $2 | |
quit | |
FTP_END | |
echo "Ftp file $2 uploaded in $1" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment