File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ from secrets import access_key ,secret_key
2+ import os
3+ import tarfile
4+ import boto3
5+ import datetime
6+ import posixpath
7+
8+ directory = "./docroot/"
9+
10+ for item in os .listdir (directory ):
11+
12+ dt = datetime .datetime .now ()
13+
14+ ts = dt .strftime ('%d-%m-%Y-%H-%M' )
15+
16+ absPath = posixpath .join (directory ,item )
17+
18+ tarName = '/tmp/backup/{}-{}.tar.gz' .format (item ,ts )
19+
20+ tar = tarfile .open (tarName ,'w:gz' )
21+
22+ tar .add (absPath )
23+
24+ tar .close ()
25+ print ('Backup for' ,absPath ,'created' )
26+ print ()
27+
28+ client = boto3 .client ('s3' ,aws_access_key_id = access_key ,aws_secret_access_key = secret_key )
29+ for file in os .listdir ('/tmp/backup' ):
30+ if '.tar' in file :
31+ upload_file_bucket = "private.s3.bucket.com"
32+ upload_file_key = "backup/{}" .format (file )
33+ path = posixpath .join ('/tmp/backup/' ,file )
34+ client .upload_file (path ,upload_file_bucket ,upload_file_key )
35+ print ('Upload to S3 successfull for' ,file )
You can’t perform that action at this time.
0 commit comments