Hinweis: Wer sich nicht mit Bash-Scripten auskennt bzw nicht die Fähigkeit besitzt, obiges Script zu debuggen und notfalls auf seine Bedürftnisse anzupassen, der möge dieses Script bitte nicht benutzen.
Ich hafte nicht für eventuelle Datenverluste oder sonstige Schäden am System.
Code: Alles auswählen
#!/bin/bash
password="yourdatabasepassword"
targetsystem="test"
sourcename="LIVE"
targetname="STAGING"
params="-h localhost -u root --password=$password"
rootpath="/home/cms/"
sqlfile="$rootpath/$targetsystem-$date-mysql.sql"
backup="$rootpath/$targetsystem-$date.tar.gz"
sourcedatabase="contenido"
destdatabase="contenido_staging"
staging="staging"
www="www"
echo "WARNING! This will sync $sourcename to $targetname."
echo "This will drop all changes to $targetname system, but"
echo "will create a backup of the $targetname first."
echo
echo -n "Are you sure (n)? "
read sure
if [ "$sure" != "y" ]; then
echo "Aborted."
exit
fi
echo
date=`date +%Y%m%d`
echo "Dumping MySQL-Database to $sqlfile"
mysqldump $destdatabase $params > $sqlfile
echo "Creating filesystem archive to $backup"
cd $rootpath
tar cfj $backup $staging
echo "Store old client configuration"
mysqldump $destdatabase $params con_clients > /tmp/clients.sql
echo "Copy database from $sourcename to $targetname"
mysqldump $sourcedatabase $params > /tmp/sync.sql
mysql $params -e "DROP DATABASE $sourcedatabase"
mysql $params -e "CREATE DATABASE $sourcedatabase"
mysql $params $destdatabase < /tmp/sync.sql
echo "Re-Installing saved client configuration"
mysql $params destdatabase -e "DROP TABLE con_clients"
mysql $params destdatabase < /tmp/clients.sql
echo "Cleaning con_code"
mysql $params destdatabase -e "DELETE FROM con_code"
echo "Copy frontend directory to $rootpath$staging/cms"
rm -rf $rootpath$staging/cms
cp -R $rootpath$www/cms/ $rootpath$staging