This is a bash script to check if a database dump has changed.
cd /srv/users/serverpilot/apps/
mysql -s -r -u root -e 'show databases' | grep -Ev 'Database|mysql|information_schema|phpmyadmin|performance_schema|sys'|
while read db
do
mysqldump --max_allowed_packet=2048M -u root $db -r /srv/users/serverpilot/apps/${db}.sql; gzip -c /srv/users/serverpilot/apps/${db}.sql > ${db}2.sql.gz;
#du -b is too precious as it gives difference even when there is not
size_previous=$(du -k ${db}.sql.gz | cut -f 1)
#size_previous=$(stat --printf='%s\n' ${db}.sql.gz)
size_new=$(du -k ${db}2.sql.gz | cut -f 1)
#size_new=$(stat --printf='%s\n' ${db}2.sql.gz)
echo $size_previous
echo $size_new
COUNT=$((size_previous-$size_new))
echo $COUNT
pwd
rm ${db}.sql
if [ "$size_previous" -eq "$size_new" ]
then
echo "${db} same! It's ok to delete the newly created"
rm ${db}2.sql.gz
else
echo "${db} NOT the same! Delete the old one and rename the new one"
rm ${db}.sql.gz
mv ${db}2.sql.gz ${db}.sql.gz
fi
done
Recent Comments