Created
July 28, 2016 23:26
-
-
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)
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
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