backupMysql.sh

#!/bin/bash

# Crontab

# 30 13 * * * sh /empresa/backupMysql.sh

# backup

# mysqldump -h HOST -u LOGIN -pSENHA --opt BANCO > backup.sql

# mysqldump -u usuario --password=senha --all-databases > backup.sql

# restore

# bzip2 -d arquivo.bz2

# mysql -h HOST -u LOGIN -pSENHA -D BANCO < restore.sql

# ---------------

# Montando particao

mount 192.168.1.2:/backup/mysql01 /mnt/backup/

# Fazendo backup de todas as tabelas

mysqldump -h 192.168.1.3 --user=root --password=root --lock-tables=0 --all-databases | bzip2 > /mnt/backup/backupBancoFull_192.168.1.3_`date "+%Y%m%d-%H%M"`.bz2

# Apagando arquivos antigos (mais de 2 dias).

find /mnt/backup/ -mtime +2 -exec rm -rf {} \;

# Desmontando particao

umount /mnt/backup