Created
December 2, 2018 16:00
-
-
Save amitsin6h/e104ff7eb994696e550c8142c94a05a5 to your computer and use it in GitHub Desktop.
Python backup script to backup website
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
#!/usr/bin/python2.6 | |
import os | |
import datetime | |
import tarfile | |
# CREATE TAR FOR FILES AND FOLDERS | |
def create_tar(path, tar_name): | |
tar = tarfile.open(tar_name, "w:gz") | |
with tar as tar_handle: | |
for root, dirs, files in os.walk(path): | |
for file in files: | |
tar_handle.add(os.path.join(root, file)) | |
tar.close() | |
# CREATE BACKUP OF public_html FOLDER | |
def backup_public_html(): | |
#FOLDER TO BACKUP | |
BACKUP_FOLDER = 'path_to/public_html/' | |
DATETIME = datetime.datetime.now().strftime("%m-%d-%y_%H-%M-%S") # REPLACE : WITH _ FROM DATETIME | |
TAR_NAME = 'MyWebsite %s.tar.gz' % DATETIME | |
# LOOK IS THE FOLDER EXIST OR NOT | |
# THEN WE WILL CREATE BACKUP OF IT | |
if(os.path.exists(BACKUP_FOLDER)): | |
# IF EXISTS = TRUE OR FALSE | |
create_tar(BACKUP_FOLDER, TAR_NAME) | |
#RUN backup_public_html() | |
backup_public_html() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment