I am trying to implement an automatic backup system for my EBS on Amazon AWS.
When I run this command as ec2-user:
/opt/aws/bin/ec2-create-snapshot --region us-east-1 -K /home/ec2-user/pk.pem -C /home/ec2-user/cert.pem -d "vol-******** snapshot" vol-********
everything works fine.
But if I add this line into /etc/crontab and restart the crond service:
15 12 * * * ec2-user /opt/aws/bin/ec2-create-snapshot --region us-east-1 -K /home/ec2-user/pk.pem -C /home/ec2-user/cert.pem -d "vol-******** snapshot" vol-********
that doesn’t work.
I checked var/log/cron and there is this line, therefore the command gets executed:
Dec 13 12:15:01 ip-10-204-111-94 CROND[4201]: (ec2-user) CMD (/opt/aws/bin/ec2-create-snapshot --region us-east-1 -K /home/ec2-user/pk.pem -C /home/ec2-user/cert.pem -d "vol-******** snapshot" vol-******** )
Can you please help me to troubleshoot the problem?
I guess is some environment problem – maybe the lack of some variable. If that’s the case I don’t know what to do about it.
Thanks.
For starters crontab does not have $PATH and you will also have to have EC2_HOME and JAVA_HOME exported.
I suggest that you make a script that has the two exports on the top and then you call the create snapshot.
So a simple
As a rule of thumb it is generally a good practice to have your backup procedure in a script.
You can find a sample script in the following link:
https://forums.aws.amazon.com/message.jspa?messageID=350163.
There are a number of scripts available that are customizable and have most of ec2 functionality automated.