- Database backup automatically using cron job
- mkdir crondb-bk
- cd crondb-bk
- create the shell script file -> touch crondb.sh
paste the following code
#!/bin/sh
now="$(date +'%d_%m_%Y_%H_%M_%S')"
filename="fitness_$now.sql".gz
backupfolder="/opt/cron-dbbk/"
fullpathbackupfile="$backupfolder/$filename"
mysqldump --user=dbusername --password=dbpassword --default-character-set=utf8 databasename --databases | gzip > "$fullpathbackupfile"
echo "mysqldump finished at "
exit 0
save file
then give permission to excute file
-
chmod +x filename.sh
-
crontab -e -> edit the cron (choose nano editor)
-
add the time and file name with full path
*/2 * * * * /opt/cron-dbbk/crondbbk.sh
then save (ctrl+x)
-
check the crontab -l (list the all cron jobs)
-
restart the cron sudo service cron restart
-
now every 2 mins excute the job
-
cron maker url http://www.cronmaker.com/