Last active
August 29, 2015 14:01
-
-
Save OnlyInAmerica/659a8831848523ed4490 to your computer and use it in GitHub Desktop.
Glacier directory Backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Makes a tarfile from every top-level directory in BACKUP_PATH | |
and transmits that to Amazon Glacier. | |
Requirements: | |
Environmental Variables: | |
+ AWS_ACCESS_KEY_ID | |
+ AWS_SECRET_ACCESS_KEY | |
Python packages: | |
+ boto | |
''' | |
BACKUP_PATH = './backup' | |
VAULT_NAME = 'openwatch-stasis' | |
VAULT_REGION = 'us-east-1' | |
import subprocess | |
import datetime | |
import tarfile | |
import os | |
import boto.glacier | |
import boto.glacier.job | |
def make_tarfile(output_filename, source_dir): | |
with tarfile.open(output_filename, "w") as tar: | |
tar.add(source_dir, arcname=os.path.basename(source_dir)) | |
print "Connecting to Glacier region" | |
glacier = boto.glacier.connect_to_region(VAULT_REGION) | |
print "Grabbing vault" | |
vault = glacier.get_vault(VAULT_NAME) | |
print "Gathering files in " + BACKUP_PATH | |
backup_dirs = [ f for f in os.listdir(BACKUP_PATH) if os.path.isdir(os.path.join(BACKUP_PATH,f)) ] | |
print "Found " + str(len(backup_dirs)) + " directories" | |
for filename in backup_dirs: | |
abs_filename = os.path.abspath(os.path.join(BACKUP_PATH, filename)) | |
print "Packaging" + filename | |
tar_filename = filename + '.tar' | |
make_tarfile(tar_filename, abs_filename) | |
print "Uploading " + tar_filename | |
uploaded_file = vault.concurrent_create_archive_from_file(filename=tar_filename) | |
print "Upload complete. File archive ID on vault: " + filename | |
print "Tada!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment