2018-01-14, 02:26 PM
2018-01-14, 02:59 PM
(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.
2018-01-15, 04:03 AM
Assuming I'm in /home/user/public/mysite and site is in /home/user/public/mysite/public
place this code in backup.sh
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