Skip to content

Instantly share code, notes, and snippets.

@seenae
Created July 31, 2015 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seenae/67ce561cf636a73cc8cd to your computer and use it in GitHub Desktop.
Save seenae/67ce561cf636a73cc8cd to your computer and use it in GitHub Desktop.
import salt.utils
import time
import pwd
import tarfile
key_id= 'kkkkk'
key_val = 'jjjjj'
#k=__salt__['pillar.get']('s3.keyid')
#k=__pillar__['s3.keyid']
#k=__salt__['pillar.item']('s3.keyid')
def homedir(user):
dest="/tmp/"+user+"-"+__grains__['fqdn']+".tar.gz"
lusr = __salt__['user.info'](user)
dt=time.strftime("%Y-%m-%d-%H:%M:%S")
dirname=user+"-"+dt+".tar.gz"
dest="/tmp/"+dirname
s3dest="homedirbackup"+"/"+__grains__['fqdn']+"/"+dirname
bucket_name="bucket-name"
if not lusr:
return "user absent"
else:
source=lusr['home']
archive = tarfile.open(dest, "w|gz")
archive.add(source, arcname=user)
archive.close()
return __salt__['s3.put'] (bucket_name,s3dest,dest)
salt "*" pillar.items s3.keyid
hostname:
----------
s3.keyid:
kkjjjfj
salt "*" pillar.items s3.key
hostname:
----------
s3.key:
kjjjjjjjjjj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment