MyBB Community Forums

Full Version: Shell script to backup directory+DB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there any script that'll backup DB+files in single file, automatically finding the db name?
(2018-01-14, 02:26 PM)rag_gupta Wrote: [ -> ]Is there any script that'll backup DB+files in single file, automatically finding the db name?

Try this:

mysqldump -u root -p --all-databases > databases-$(date +%Y-%m-%d_%H-%M-%S).sql

This will export all of the databases found within your MySQL server into a single file.
Assuming I'm  in /home/user/public/mysite and site is in /home/user/public/mysite/public 

place this code in backup.sh


DB="your database name"

if mysqldump -u root -p $DB > /tmp/$DB.sql
then
d=`date|tr " :" --`
pwd=`pwd`
BASEDIR=`basename $pwd`
file="$BASEDIR-$d"
echo "file=$file  d=$BASEDIR"

if tar cvzf /tmp/$file.tar.gz  .  -C /tmp/ $DB.sql
then
echo "Successfully backed up in :/tmp/$file.tar.gz"
else
echo "Backup failed"
fi

fi