0

I am trying to make backup of mysql database autoatically using crontab but when I but the command directly int /etc/crontab file the backup created successfully

19 16 * * * root mysqldump -u root -prootroot -h192.168.4.5 radius  | gzip > /etc/freeradius/nh.sql.gz

the above command work nice but when I but this command in file and execute the file from crontab the database can not be created this is the content of /etc/freeradius/backup.sh

mysqldump -u root -prootroot -h192.168.4.5 radius | gzip > /etc/freeradius/nh.sql.gz

and this is the content of crontab file

46 16     * * *   root    /etc/freeradius/backup.sh

but there is no any thing happen even if the command is executed as I saw in syslog file

1
  • I am betting you have a bug in your script or something, and since you have no MTA you aren't seeing the results. Maybe send your output to a file temporarily. 46 16 * * * root /etc/freeradius/backup.sh > /path/mylogfile.
    – Zoredache
    Aug 24, 2017 at 6:51

2 Answers 2

0

Create a file db_dump.sh -> script to dump the contents of a database into separate files in the directory "/backups/"

#!/bin/bash

mysqldump -x --add-drop-table  --all-databases > /backups/mysqldb-`date +%F-%I%p`.sql

/usr/bin/mysql -e 'show databases' | /usr/bin/awk '{print $1}' | /bin/grep -v "^Database$" | /usr/bin/xargs -i{} /usr/bin/mysqldump --single-transaction --opt -Q -r /backups/`date +%F-%I%p`-{}.sql {}

gzip -q /backups/*.sql

Make sure that db_dump.sh is executable.

Add to crontab, in my case 10 p.m., daily:

crontab -e

and add:

0 22 * * * /db_dump.sh

For a full backup and nice explanation visit: https://github.com/zauberware/automated-server-backups

0

Make your backup.sh into a proper shell script:

#!/bin/bash
mysqldump -u root -prootroot -h192.168.4.5 radius | | gzip > /etc/freeradius/nh.sql.gz

and don't forget to make it executable with

 chmod 700 /etc/freeradius/backup.sh
6
  • thank you for your replay but there is nothing happened Aug 24, 2017 at 6:36
  • What do the log files say?
    – Sven
    Aug 24, 2017 at 6:37
  • Aug 24 09:35:01 muhammad-VirtualBox CRON[1771]: (root) CMD ( /etc/freeradius/backup.txt ) Aug 24 09:35:01 muhammad-VirtualBox CRON[1770]: (CRON) info (No MTA installed, discarding output) Aug 24, 2017 at 6:38
  • Not sure if it is the only issue but the double pipe (... radius | | gzip > ...) present in both the question, and quoted in this answer is probably not helping.
    – Zoredache
    Aug 24, 2017 at 6:49
  • no no it is my typing wrong it is just 1 pipe in the file Aug 24, 2017 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.