I have a Ubuntu 9.10 image running on Amazon EC2 and I've setup a backup script ec2-consisten-snapshot.
I'm able to run the script from SSH, and everything works peachy.
sudo ec2-consistent-snapshot --mysql --xfs-filesystem /vol vol-xxxxxxx >>/mnt/backup.log 2>&1
However when I schedule a cron job in sudo crontab -e, the script runs but gives me errors.
12 18 4 2 * ec2-consistent-snapshot --mysql --xfs-filesystem /vol vol-xxxxxxx >>/mnt/backup.log 2>&1
ec2-consistent-snapshot: ERROR: Can't find AWS access key or secret access key at /usr/bin/ec2-consistent-snapshot line 76.
xfs_freeze: cannot unfreeze filesystem mounted at /vol: Invalid argument
ec2-consistent-snapshot: ERROR: xfs_freeze -u /vol: failed(256)
The AWS access keys are located under $HOME/.awssecret and work fine if you don't run it from cron
Can someone point me what I need to do, I've been trying to figure this out for past week.
Also how do I troubleshoot xfs_freeze that works fine from command line.
Thank you very much!
Answer
sudo crontab -e
edits root's crontab right? When you say you have $HOME/.awssecret, what is $HOME? root's home or yours?
You might want to think about using /etc/cron.d, you can additionally add the name of the user to execute the script as in these files (e.g. caution: slightly different syntax for the scripts)
Edit (answering your question in the comment):
Create a file /etc/cron.d/myEc2Crontab
make it contain:
SHELL=/bin/sh
PATH=whatever you need as your path
12 18 4 2 * root ec2-consistent-snapshot --mysql --xfs-filesystem /vol vol-xxxxxxx >>/mnt/backup.log 2>&1
note the added 'root' just after the time specification, prior to your command. This specifies the user the command runs as.
Comments
Post a Comment