v1 shell script

su@silene1:/w3/backups/ more backup.sh

foreach i (users pre_booking textpv LocalNumbers MainLicences companies) 
        /usr/local/mysql/bin/mysqldump -h servername -u userMySQL -pPasswdMySQL dbName $i | gzip > $i_`date +\%d_\%m_\%Y_\%H:\%M`.sql.gz
end

v2

crontab root:

00 23 * * * /home/radeff/bin/mysqldumplocal.sh  > /dev/null 2>&1

et le programme:

#! /usr/bin/sh
# Usage:
# mysqldumplocal.sh
# sauvegarder toutes les bases MySQL sauf certaines
# Required:
# mysqldump, awk, gzip
# source http://lists.nyphp.org/pipermail/talk/2004-October/012361.html
# Adapted FR, frederic.radeff@unige.ch, www.unige.ch
# History 1 octobre 2008, created FR
############
login=root #root login mysql
password=xxxxxx #passwd mysql
#path to mysql data directory
mysql_dir=/usr/local/mysql/data #on unix
#path to backup
mysql_backup=/home/radeff/backup/mysql #on unix

#db to excludes
test=test
#test1=achats_dinf
#purge files before backup
rm /export/backup/mysql/*.sql.*

#find the db and exclude somes
#ls -al $mysql_dir   | grep ^d  | egrep -v '\.[\.]?' | grep -v $test | grep -v $test1 | awk '{print $8}' | while read i
ls -al $mysql_dir   | grep '^d'  | egrep -v '\.[\.]?' | grep -v $test | awk '{print $9}' | while read i
#begin loop on results
do
#dump db, name prededed by date, extension sql
  echo "mysqldump $i > $mysql_backup/$i.sql"
  /usr/local/mysql/bin/mysqldump -u $login -p$password $i > $mysql_backup/$i.sql
#zip the backups
  gzip $mysql_backup/$i.sql
done
#end loop on results
#purge files after backup - seems useless
#rm /w3/backups/mysql/*.sql
#purge old files if any
find $mysql_backup -mtime +$memoire -name "*.gz" -type f -exec rm {} \;
chmod -R 700 $mysql_backup
echo "Backup OK on all MySQL requested DB's"
# 

  • info/mysqlbackupcertainesbasesradeff.txt
  • Dernière modification: 2018/07/18 09:46
  • par radeff