# Retrieve tables list tables=$(echo 'SHOW TABLES' | $MYSQL -s -h $DB_HOST -u $DB_USER -p$DB_PASS -P $DB_PORT -D $DB_NAME); if [ ! "$tables" ] ; then echo "ERROR: can not retrieve tables list" exit 1; fi # check if exists backup directory if [ ! -d $PROJECT_PATH/$DB_BACKUP_DIR/$BRANCHE_PATH ] ; then if [ ! "$($SVN info $REPOSITORY_URL/$PROJECT_NAME/$DB_BACKUP_DIR 2>/dev/null | grep '^Revision:')" ] ; then mkdir -p $PROJECT_PATH/$DB_BACKUP_DIR/$BRANCHE_PATH $SVN add --parents $PROJECT_PATH/$DB_BACKUP_DIR else CURRENT_DIR=`pwd` cd $PROJECT_PATH/ $SVN up --non-recursive $DB_BACKUP_DIR cd $CURRENT_DIR if [ ! "$($SVN info $REPOSITORY_URL/$PROJECT_NAME/$DB_BACKUP_DIR/$BRANCHE_PATH 2>/dev/null | grep '^Revision:')" ] ; then mkdir -p $PROJECT_PATH/$DB_BACKUP_DIR/$BRANCHE_PATH $SVN add --parents $PROJECT_PATH/$DB_BACKUP_DIR/$BRANCHE_PATH else CURRENT_DIR=`pwd` cd $PROJECT_PATH/ $SVN up $DB_BACKUP_DIR/$BRANCHE_PATH cd $CURRENT_DIR fi fi fi # Delete current dumps for dump in $(find $DB_BACKUP_PATH -name '*.sql' -type f) ; do rm -f $dump done # Create tables dumps for table in $tables ; do fileName="$DB_BACKUP_PATH/$table.sql" $MYSQL_DUMP --compact -Q --hex-blob -c -e --default-character-set=utf8 -B $DB_NAME -h $DB_HOST -u $DB_USER -p$DB_PASS -P $DB_PORT --tables $table > $fileName if [ ! -f $fileName -o ! -s $fileName ] ; then echo "ERROR: can not create dump for table '$table'" exit 1 fi done # Remove unnecessary files from repository for dump in $($SVN st $DB_BACKUP_PATH | grep ^! | awk '{print $2}') ; do $SVN del $dump done # Add new files to repository for dump in $($SVN st $DB_BACKUP_PATH | grep ^? | awk '{print $2}') ; do $SVN add $dump done #echo 'All done. Commit required'; $SVN ci -m "DB structure update. NOTASK" $PROJECT_PATH/$DB_BACKUP_DIR exit 0