Situatie
Vrem sa facem back-up unei baze de date mysql , apoi baza de date sa fie uploadata pe un server FTP
Solutie
Deschidem un editor de text in terminal
ex :
nano backup.sh
introducem urmatorul script in fisier :
#!/bin/bash
#############################################################
# Backup baza de DATA mysql, upload backup pe un server ftp #
#############################################################
DATA=`date +%d%b%y`
BACKUP_LOCAL=”/backup/”
DB_NAME=”test”
DB_USER=”root”
PAROLA_DB=”parola baza de date”
SERVER_FTP=”ftp.serverftp.ro”
UTILIZATOR_FTP=”utilizator ftp”
PAROLA_FTP=”parola utilizatorului ftp”
FOLDER_UPLOAD_FTP=”/backup/”
FISIER_LOGURI=/backup/backup-DATA.log
############### BACKUP LOCAL ########################
mysqldump -u $DB_USER -p$PAROLA_DB $DB_NAME | gzip > $BACKUP_LOCAL/$DB_NAME-$DATA.sql.gz
############### UPLOAD PE SERVER FTP ################
ftp -n $SERVER_FTP << EndFTP
user “$UTILIZATOR_FTP” “$PAROLA_FTP”
binary
hash
cd $FOLDER_UPLOAD_FTP
#pwd
lcd $BACKUP_LOCAL
put “$DB_NAME-$DATA.sql.gz”
bye
EndFTP
if test $? = 0
then
echo “BAZA DE DATE A FOST SALVATA CU SUCCES PE SERVERUL FTP
Nume fisier $DB_NAME-$DATA.sql.gz ” > $FISIER_LOGURI
else
echo “Eroare” > $FISIER_LOGURI
Apoi salvam cu CTRL X , apasam ENTER
Rulam setul de comenzi:
chmod +x backup.sh
./backup.sh
Leave A Comment?