You are not logged in.
i have a script to run mysqldump that i found somewhere, i thought it was found under either the LAMP wiki, or the mysql wiki, but im not finding it when looking again.
i am not well versed in this one so i threw a script inside cron.daily so i didnt hvae to yet edit crontab.
#!/bin/bash
#THISDIR=$(dirname $(readlink -f "$0"))
NOW=$(date +"%Y-%m%d")
PATH="/srv/backup/"$NOW"_db_backup.gz"
mysqldump --single-transaction --flush-logs --master-data=2 --all-databases \
| gzip > $PATH
echo 'purge master logs before date_sub(now(), interval 7 day);' | mysqli was getting
command not foundfor gzip, mysql, and mysqldump.
i added the full paths to the commands to squelch some errors
#!/bin/bash
#THISDIR=$(dirname $(readlink -f "$0"))
NOW=$(date +"%Y-%m%d")
PATH="/srv/backup/"$NOW"_db_backup.gz"
/usr/bin/mysqldump --single-transaction --flush-logs --master-data=2 --all-databases \
| /usr/bin/gzip > $PATH
echo 'purge master logs before date_sub(now(), interval 7 day);' | /usr/bin/mysql, and now im getting more errors. i am running the command directly from the directory its in, will this even work?
# ll
total 24
drwxr-xr-x 2 root root 4096 Dec 13 12:24 .
drwxr-xr-x 53 root root 4096 Dec 13 07:39 ..
-rwxr--r-- 1 root root 668 Oct 10 05:57 logrotate
-rwxr--r-- 1 root root 806 Jun 27 06:22 man-db
-rwxr-xr-- 1 root root 311 Dec 13 12:18 mysqldump
-rwxr--r-- 1 root root 94 Oct 21 07:33 shadow
# ./mysqldump
mysqldump: Got error: 1045: "Access denied for user 'root'@'localhost' (using password: NO)" when trying to connect
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)furthermore, there is a couple empty non working .gz files inside my backup directory, so its doing something when ran as an actual cron job, its just not dumping the data,
permissions on the /srv/backup directory are as follows
drwxrwx--- 2 root dev 4096 Dec 13 10:03 backupEdit:
crap on me, it looks like now that i added the full paths, its overcoming the command not found error, OBVIOUSLY, but what i didnt realize is the error coming back is not a file system permission error, its a mysql error, DOH. so looks like i might just have to correct the command. what can do i about not having to add the password in this bash script? or do i need to. if so, on what part of the command?
Last edited by wolfdogg (2013-12-14 02:25:15)
Offline
Ok, im open to better suggestions, i.e. if theres something more secure, but i made a solution
i made a new user called cron in mysql, and gave it basic privileges (LOCK TABLES, RELOAD, SELECT, SUPER) only.... then in my script i had to add --password and --user in both places
see below
#!/bin/bash
#THISDIR=$(dirname $(readlink -f "$0"))
NOW=$(date +"%Y-%m%d")
PATH="/srv/backup/"$NOW"_db_backup.gz"
/usr/bin/mysqldump --user=cron --password=mypass --single-transaction --flush-logs --master-data=2 --all-databases | /usr/bin/gzip > $PATH
echo 'purge master logs before date_sub(now(), interval 7 day);' | /usr/bin/mysql --user=cron --password=mypassdoes this seem fair? or does privs like SUPER or any others mentioned open a bunch of holes?
Offline
I think it may be a bit more secure if you use visudo.
You set the script to be run by the cron user you created but with no password, eg:
cron ALL=NOPASSWD: /path/to/your/script/cron
That way you do not have to embed the password in the script as you did.
R.
Offline