Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Backing up the OVH server, checking the archive and sending it through FTP
  4. #
  5.  
  6. # Copyright © 2013 Carl Chenet <chaica@ohmytux.com>
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>
  19.  
  20. BACKUPHOME=/home/backups
  21. FTPUSER=ftpbackupser
  22. FTPPASS=S0m3Th1nGH4rD
  23. FTPSERVER=ftp.server.com
  24. SERVER=youservername
  25. MYSQLUSER=backup
  26. MYSQLPASS=S0m4Th1nGTr1cKy
  27. PKGLIST=$BACKUPHOME/installed-packages
  28. DBDUMP=$BACKUPHOME/mysqldumpall.sql
  29. ARCHIVE=$BACKUPHOME/$SERVER-backup-`date +%d-%m-%Y`.tar.bz2
  30. ADMINEMAIL=your.email@domain.com
  31.  
  32. # create BACKUPHOME if not exists
  33. mkdir -p $BACKUPHOME
  34. # get installed Debian packages
  35. dpkg --get-selections| awk -F' ' '{print $1}' > $PKGLIST
  36. if [ $RETVAL != 0 ];then
  37. echo "Issue while using dpkg --get-selections of $SERVER on $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
  38. fi
  39. # get mysql database
  40. mysqldump -u$MYSQLUSER -p$MYSQLPASS --all-databases > $DBDUMP
  41. if [ $RETVAL != 0 ];then
  42. echo "Issue while performing mysqldump of $SERVER on $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
  43. fi
  44. # get directories and files
  45. tar --preserve-permissions --preserve-order -j -c -f $ARCHIVE /etc /var /home /opt /usr/local/bin $DBDUMP \
  46. --exclude=/var/lib/mysql/data \
  47. --exclude=$BACKUPHOME/$SERVER-backup* \
  48. --exclude=/var/cache/apt/archives > /dev/null 2>&1
  49. # remove one-month-old archive on the FTP
  50. lftp -e "rm -f $SERVER-backup-`date -d "-10 day" +%d-%m-%Y`.tar.bz2;exit" -u $FTPUSER,$FTPPASS $FTPSERVER > /dev/null 2>&1
  51. if [ $RETVAL != 0 ];then
  52. echo "Issue while removing the old archive of $SERVER on $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
  53. fi
  54. # send the archive to ftp account
  55. lftp -e "mput $ARCHIVE;exit" -u $FTPUSER,$FTPPASS $FTPSERVER > /dev/null 2>&1
  56. RETVAL=$?
  57. if [ $RETVAL != 0 ];then
  58. echo "Issue while uploading the archive from $SERVER to $FTPSERVER" | mail -s "Issue while uploading $ARCHIVE" $ADMINEMAIL
  59. fi
  60. # remove the local backups
  61. rm -f $PKGLIST $DBDUMP $ARCHIVE
  62. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement