MySQL Backup to a share

  • Create a share on a server
  • Install cifs-utils: apt-get install cifs-utils
  • Create a folder under /mnt for mounting:
    mkdir /mnt/backup
  • Inside of /etc/fstab define the mountpoint:
//backupserver/Linux_Backups   /mnt/backup   cifs    credentials=/etc/cifspw    0       0
  • Create /etc/cifspw with credentials für a „mounting-user“

> Ubuntu 12

username=linuxmountpassword=linuxmountpassworddomain=DOMAIN

< Ubuntu 13

username=DOMAIN\linuxmountpassword=linuxmountpassword
  • Try via mount -a if mounting works and verify output of df or simply go to /mnt/backup (cd /mnt/backup)
  • Create a file called mysqlbackup.sh inside of /usr/sbin and add this content:
#user='root'
#password='youshouldcreateabackupuser'
user=backup
password='password'
for db in 'mysqlshow -u $user -p$password | sed -n -e "s/^| \([^ ]*\)[ ]*|$/\1/p"'  
do mysqldump --opt -u $user -p$password $db > /mnt/backup/ /mysql/$db.sqldone

After creation do chmod a+x mysqlbackup.sh so that the script can be executed

  • To automate the job create a cronjob under /etc/cron.d called mysql_backup (or do it via crontab –e)
00 02 * * *     root    /usr/sbin/mysqlbackup.sh >/dev/null 2>&1
0

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.