Steve’s Python Utils – New Repo

An assortment of python [shell] scripts for various minor tasks.  In this case an assortment starts with one.

The GitHub repo is here: steves-python-utils

My first addition is a synchronization script, called dir2s3sync.py, I use to sync a local folder/directory with one on Amazon Web Services S3.

200px-AWS_Simple_Icons_Storage_Amazon_S3_Bucket_with_Objects.svg

Given a local directory and a S3 bucket and remote subdirectory.  It compares the local files, including subdirectories, corresponding to S3.  If a new file appears within the local subdirectory it is uploaded.  Also, if a timestamp indicating modification to a local file where the date/time is out of sync with its S3 counterpart, the file is also uploading overwriting the S3 copy of it.

Because of possible timezone differences between the local computer and S3, the script takes a timezone difference as a parameter (in hours).

Example usage:

python dir2s3sync.py -4 ~/wp/wp-content/uploads/ uploads

Parameters:

-4 is the timezone difference from GMT in this case.  So the server this is being run on is in Atlantic Time.

~/wp/wp-content/uploads/ is the local file path

uploads is the remote path on S3.

Note: the S3 security credentials and bucket name are specified within dir2s3sync.py

The underlying S3 calls are done through the python boto package.

My current use of this is to trigger a synchronization of WordPress Media uploads to S3.

wordpress-logo-stacked-rgb

I have a few other python scripts kicking around that I will eventually sanitize for public consumption in the steves-python-utils GitHub repository.