Backup mysqldump usando Shell Script
Publicado por CalRaiden© 11/03/2009
[ Hits: 16.868 ]
Homepage: www.calraiden.com.br
Esses dias fiz um script em php para realizar um mysql_dump. Porém, procurando na internet, encontrei um em shell, que em questão de perfomance mostrou-se bastante superior. Fiz algumas alterações e consertei um pequeno bug, sendo que realizava backup de todo mysql.
No meu caso só interessava backup das tabelas de um banco. Retirei a compactação atráves GZIP, mas isso está exigindo muitos recursos do server e ainda aumentava o tempo de execução do script. Por essa razão tirei, caso alguém veja o script original, saberá o que estou falando.
Acrescentei um log simples no final, apenas para saber quando começou a executar e quando terminou.
#!/bin/bash # Shell script to backup MySql database # To backup Nysql databases file to /backup dir and later pick up by your # script. You can skip few databases from backup too. # For more info please see (Installation info): # http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/01/mysql-backup-script.html # Last updated: Aug - 2005 # -------------------------------------------------------------------- # This is a free shell script under GNU GPL version 2.0 or above # Copyright (C) 2004, 2005 nixCraft project # Feedback/comment/suggestions : http://cyberciti.biz/fb/ # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------ #HORA INICIO DO SCRIPT --OPCIONAL, APENAS PARA SABER QUANDO COMEÇOU A EXECUTAR E TERMINOU START="$(date)" #configuration MyUSER="root" # USERNAME MyPASS="" # PASSWORD MyHOST="localhost" # Hostname # Linux bin paths, change this if it can't be autodetected via which command MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" CHOWN="$(which chown)" CHMOD="$(which chmod)" # Backup Dest directory, change this if you have someother location DEST="/root" # Main directory where backup will be stored MBD="$DEST/bkp_mysql_austin" # Get data in dd-mm-yyyy format NOW="$(date +"%d-%m-%Y")" # File to store current backup file FILE="" # Store list of databases TABLES="" # BACKUP these databases DATABASE="live2go" mkdir $MBD/$NOW # Only root can access it! $CHOWN 0.0 -R $MBD $CHMOD 0600 $MBD # Get all database list first TABLES="$($MYSQL -u $MyUSER -h $MyHOST --password=$MyPASS $DATABASE -Bse 'SHOW TABLES')" for tables in $TABLES do FILE="$MBD/$NOW/$tables.gz" # do all inone job in pipe, # connect to mysql using mysqldump for select mysql database # and pipe it out to gz file in backup dir :) $MYSQLDUMP --add-drop-table --extended-insert --no-create-db -u $MyUSER -h $MyHOST --password=$MyPASS $DATABASE $tables > $FILE done #HORA FIM DO SCRIPT --OPCIONAL, APENAS PARA SABER QUANDO COMEÇOU A EXECUTAR E TERMINOU END="$(date)" #LOG SCRIPT touch $MBD/$NOW/$NOW echo $START >> $MBD/$NOW/$NOW echo $END >> $MBD/$NOW/$NOW #FIM DO LOG DO SCRIPT exit;
Corrigindo problema com Splash no Ubuntu
Mudar aleatoriamente o papel de parede no GNOME 3
Instalar Unreal Tourment no Linux
Gentoo: detectando impressoras de rede e como fixar uma impressora por IP
Como o GNOME conseguiu o feito de ser preterido por outras interfaces gráficas
Gentoo binário em 2026: UEFI, LUKS, Btrfs e Systemd
Trabalhando Nativamente com Logs no Linux
Jogando Daikatana (Steam) com Patch 1.3 via Luxtorpeda no Linux
Por que sua empresa precisa de uma PKI (e como automatizar EMISSÕES de certificados via Web API)
Instalando NoMachine no Gentoo com Systemd (acesso Remoto em LAN)
Gentoo: Trocando wpa_supplicant pelo iwd no NetworkManager (Systemd)
O que houve com slackware ??? (12)
Alterar conteúdo de dica [RESOLVIDO] (3)
Vou destruir sua infância:) (5)









