Skip to content

Il sito di Ivan Piffer

Narrow screen resolution Wide screen resolution Increase font size Decrease font size Default font size    Default color brown color green color red color blue color
You are here: HOME arrow Informatica arrow Articoli interessanti arrow Uno script shell per il backup dei database mysql tabella per tabella e copia via FTP
Skip to content

Chatta con me


MySQL
Uno script shell per il backup dei database mysql tabella per tabella e copia via FTP PDF Stampa E-mail
Valutazione utente: / 0
ScarsoOttimo 
Scritto da Ivan Piffer   
martedì 07 ottobre 2008

http://www.masterand.com/images/mysql_logo.gif ... e con un po di modifiche via SSH(ma bisogna avere l'autenticazione con i certificati e non via password)

 
#!/bin/sh
 
# System + MySQL backup script
 
# Copyright (c) 2008 Marchost
 
# This script is licensed under GNU GPL version 2.0 or above
 
# ---------------------------------------------------------------------
 
 
 
#########################
 
######TO BE MODIFIED#####
 
 
 
### System Setup ###
 
BACKUP=YOUR_LOCAL_BACKUP_DIR
 
 
 
### MySQL Setup ###
 
MUSER="MYSQL_USER"
 
MPASS="MYSQL_USER_PASSWORD"
 
MHOST="localhost"
 
 
 
### FTP server Setup ###
 
FTPD="YOUR_FTP_BACKUP_DIR"
 
FTPU="YOUR_FTP_USER"
 
FTPP="YOUR_FTP_USER_PASSWORD"
 
FTPS="YOUR_FTP_SERVER_ADDRESS"
 
 
 
######DO NOT MAKE MODIFICATION BELOW#####
 
#########################################
 
 
 
### Binaries ###
 
TAR="$(which tar)"
 
GZIP="$(which gzip)"
 
FTP="$(which ftp)"
 
MYSQL="$(which mysql)"
 
MYSQLDUMP="$(which mysqldump)"
 
 
 
### Today + hour in 24h format ###
 
NOW=$(date +"%d%H")
 
 
 
### Create hourly dir ###
 
 
 
mkdir $BACKUP/$NOW
 
 
 
### Get all databases name ###
 
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
 
for db in $DBS
 
do
 
 
 
### Create dir for each databases, backup tables in individual files ###
 
  mkdir $BACKUP/$NOW/$db
 
 
 
  for i in `echo "show tables" | $MYSQL -u $MUSER -h $MHOST -p$MPASS $db|grep -v Tables_in_`;
 
  do
 
    FILE=$BACKUP/$NOW/$db/$i.sql.gz
 
    echo $i; $MYSQLDUMP --add-drop-table --allow-keywords -q -c -u $MUSER -h $MHOST -p$MPASS $db $i | $GZIP -9 > $FILE
 
  done
 
done
 
 
 
### Compress all tables in one nice file to upload ###
 
 
 
ARCHIVE=$BACKUP/$NOW.tar.gz
 
ARCHIVED=$BACKUP/$NOW
 
 
 
$TAR -cvf $ARCHIVE $ARCHIVED
 
 
 
### Dump backup using FTP ###
 
cd $BACKUP
 
DUMPFILE=$NOW.tar.gz
 
$FTP -n $FTPS <<END_SCRIPT
 
quote USER $FTPU
 
quote PASS $FTPP
 
cd $FTPD
 
mput $DUMPFILE
 
quit
 
END_SCRIPT
 
 
 
### Delete the backup dir and keep archive ###
 
 
 
rm -rf $ARCHIVED

 Trovato QUI, grazie a HOWTOFORGE.

 

Commenti
Nuovo Cerca RSS
Commenta
Nome:
Email:
 
Website:
Titolo:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."


MySQL
Ultimo aggiornamento ( martedì 07 ottobre 2008 )
 
< Prec.   Pros. >