Skip to content

Instantly share code, notes, and snippets.

@rms1000watt
Created July 28, 2016 23:26
Show Gist options
  • Save rms1000watt/150ac0d5998a25500e32ed67c3e6779d to your computer and use it in GitHub Desktop.
Save rms1000watt/150ac0d5998a25500e32ed67c3e6779d to your computer and use it in GitHub Desktop.
Python script to backup, delete, copy files from the home directory to a root directory (used on Ubuntu)
import os
import glob
import time
import shutil
def main():
appPath = '/etc/appName'
date = str(int(time.time()))
folders = glob.glob('staging/*')
latest = max([int(v.split('/')[1]) for v in folders])
basePath = [v for v in folders if str(latest) in v][0]
# Backup
try: os.mkdir('bak')
except: pass
os.mkdir('bak/%s' %(date))
shutil.copytree('%s/api' %(appPath), 'bak/%s/api' %(date))
# Remove
shutil.rmtree('%s/api' %(appPath))
# Copy
shutil.copytree(basePath, '%s/api' %(appPath))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment