Skip to content

Instantly share code, notes, and snippets.

@errogaht
Created December 16, 2016 05:17
Show Gist options
  • Save errogaht/29c4676a0e81631fda7c15e736edab6c to your computer and use it in GitHub Desktop.
Save errogaht/29c4676a0e81631fda7c15e736edab6c to your computer and use it in GitHub Desktop.
backup mysql + files to FTP
site_name="site.ru"
path_to_site="/home/admin/web/site.ru/public_html"
path_for_backups="/home/admin/web/site.ru/backups_tmp"
db_name="don_tur"
db_user="don_tur"
#db_passsword=
db_host="localhost"
ftp_login=""
ftp_pass=""
ftp_host=""
# бэкап файлов
cd $path_to_site
mkdir ${path_for_backups}
tar -cvjf ${path_for_backups}/backup_${site_name}_files.`date +%Y-%m-%d`.tar.bz2 .
# бэкап бд
/usr/bin/mysqldump --single-transaction -u${db_user} -p5caeDJ9h7WxtqY8G -h${db_host} ${db_name} > ${path_for_backups}/${db_name}.`date +%Y-%$
/bin/bzip2 -f ${path_for_backups}/${db_name}.`date +%Y-%m-%d`.sql
# отправляем на ftp
cd ${path_for_backups}
cd ../
mkdir ftp
curlftpfs ftp://${ftp_login}:${ftp_pass}@${ftp_host}/ ftp
cd ftp
mkdir ${site_name}
cd ${site_name}
mv ${path_for_backups}/* .
/usr/bin/find . -name '*.sql.bz2' -type f -mtime +15 -exec rm {} \;
/usr/bin/find . -name '*.tar.bz2' -type f -mtime +15 -exec rm {} \;
cd ../../
fusermount -u ftp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment