-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
39 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from .constants import Constants | ||
from .backup import Backup |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from backedup import Constants | ||
from backedup import Backup | ||
|
||
import datetime | ||
import json | ||
import logging | ||
import os | ||
import shutil | ||
|
||
|
||
def main(): | ||
logging.basicConfig(filename='backedup.log', level=logging.INFO) | ||
create_backedup_folder() | ||
if not did_backup_today(): | ||
json_configs = get_config_json_file() | ||
backup = Backup(json_configs) | ||
backup.create_backedup_folder() | ||
if not backup.did_backup_today(): | ||
backup_directory = create_backup_directory() | ||
create_backup(backup_directory) | ||
backup.start_backup(backup_directory) | ||
print(Constants.DONE) | ||
|
||
def get_config_json_file(self): | ||
""" | ||
get_config_json_file | ||
def create_backedup_folder(): | ||
if os.path.isdir(Constants.DEST_FOLDER): | ||
print(Constants.FOLDER_EXIST) | ||
return True | ||
else: | ||
os.mkdir(Constants.DEST_FOLDER) | ||
|
||
|
||
def did_backup_today(): | ||
dest_folder_list = os.listdir(Constants.DEST_FOLDER) | ||
for folder in dest_folder_list: | ||
if str(datetime.date.today()) in folder: | ||
print(Constants.OUTPUT_FOLDER_EXIST) | ||
return True | ||
else: | ||
print(Constants.STARTING_UPDATE) | ||
return False | ||
|
||
|
||
def create_backup(backup_directory): | ||
shutil.copytree(src=Constants.SRC_FOLDER, | ||
dst=backup_directory, | ||
ignore=_logpath) | ||
|
||
- Gets the config JSON file and returns the output | ||
""" | ||
logging.info("Current directory: " + os.getcwd()) | ||
logging.info("Loading JSON config file.") | ||
with open(Constants.CONFIG_LOCATION, 'r') as file: | ||
return json.load(file) | ||
|
||
def create_backup_directory(): | ||
""" | ||
create_backup_directory | ||
""" | ||
backup_directory = Constants.DEST_FOLDER + \ | ||
Constants.NEW_UPDATE_FOLDER + str(datetime.date.today()) | ||
if os.path.isdir(backup_directory): | ||
print(Constants.OUTPUT_FOLDER_EXIST) | ||
return backup_directory | ||
|
||
|
||
def _logpath(path, names): | ||
logging.info('Copying %s' % path) | ||
return [] | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from backedup import Constants | ||
|
||
import datetime | ||
import logging | ||
import os | ||
import shutil | ||
|
||
class Backup: | ||
|
||
def __init__(self, configs): | ||
self.config = configs | ||
self.destination_folder = self.config["destFolder"] | ||
self.source_folder = self.config["srcFolder"] | ||
|
||
def create_backedup_folder(self): | ||
""" | ||
create_backedup_folder | ||
""" | ||
if os.path.isdir(self.destination_folder): | ||
logging.info("Destionation folder does exist. Continuing forward with backup.") | ||
return True | ||
else: | ||
logging.info("Destionation folder does not exist.") | ||
logging.info("Creating destionation folder for backup.") | ||
os.mkdir(self.destination_folder) | ||
|
||
def create_source_folder(self): | ||
pass | ||
|
||
def did_backup_today(self): | ||
""" | ||
did_backup_today | ||
""" | ||
dest_folder_list = os.listdir(self.destination_folder) | ||
for folder in dest_folder_list: | ||
if str(datetime.date.today()) in folder: | ||
print(Constants.OUTPUT_FOLDER_EXIST) | ||
return True | ||
else: | ||
print(Constants.STARTING_UPDATE) | ||
return False | ||
|
||
def start_backup(self, backup_directory): | ||
""" | ||
start_backup | ||
""" | ||
shutil.copytree(src=Constants.SRC_FOLDER, | ||
dst=backup_directory, | ||
ignore=self._logpath) | ||
|
||
def _logpath(self, path, names): | ||
logging.info('Copying %s' % path) | ||
return [] | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#!/usr/bin/env python3 | ||
|
||
|
||
class Constants: | ||
DONE = "DONE!" | ||
FOLDER_EXIST = "The Backedup folder exist!" | ||
DEST_FOLDER = "/media/passport/backedup" | ||
NEW_UPDATE_FOLDER = "/backedup_" | ||
DEST_FOLDER = "./dest" | ||
NEW_UPDATE_FOLDER = "./new_folder" | ||
OUTPUT_FOLDER_EXIST = "An update has already occurred today!" | ||
SRC_FOLDER = "/home/chris" | ||
SRC_FOLDER = "./src_folder" | ||
STARTING_UPDATE = "Starting Backedup..." | ||
CONFIG_LOCATION = "./backedup.json" |