March 10, 2015

Using s3cmd in a cron job

s3cmd is a simple command line tool for managing data in your S3 storage buckets. I use it to store lovetap backups. It's very easy to set up - the first time you run it, it asks for your S3 settings and stores them. Once that's done, syncing data to S3 is a simple call that looks similar to this:

s3cmd sync /var/backups/mongodb/test s3://test/

That's nice and all, but I wanted to sync to S3 in a cron job right after the daily mongo backups complete, but just couldn't get it to work. I finally realized that cron jobs run under the root user and that that user doesn't have s3cmd configured. All I had to do was copy my settings to the root user's home directory:

cp -i /home/stefan/.s3cfg /root/.s3cfg

That's it. Hope this will help someone who's running into the same problem.

Comments powered by Disqus