Save BackUp File in specific location

madridista

New Member
Joined
Dec 31, 2019
Messages
1
Reaction score
0
Credits
0
Hi there

I am pretty new in the Linux world. I am just setting up a MySQL Database and now I want to create an automatic backup job for all the databases.

I'm using the following script to create the backup:

#!/bin/bash
DATE=$(date +%d%m%Y-%H)
mysqldump -u backupuser -p'12345' --all-databases > alldb-"$DATE".sql
sleep 5
pixz alldb-"$DATE".sql


My crontap file:
Mailto=[email protected]
30 14 * * * /mnt/disk2/backupdb.sh


The script is working fine, so the backup is created as wanted. But I want to change the location of the created file. Now the file is created in my userhome but I would like to change it to the location /mnt/disk2 or another location beside my userhome.

How can I do this? And what do I need to do that I receive the backup mails? As you can see I wrote in the crontap file MAILTO=[email protected] but I never received a mail.

Really appreciate your help!
 


If disk2 is a directory under mount it is simply changing one line. When you write the file ">" you just need to specify the location. Change mysqldump -u backupuser -p'12345' --all-databases > alldb-"$DATE".sql to mysqldump -u backupuser -p'12345' --all-databases > /mnt/disk2/alldb-"$DATE".sql . Or you can add a cd command to move to the directory before running mysqldump.

To send a file as an email body use the mail command.

mail -s "Subject" [email protected] < FileforEmailBody
 

Staff online


Top