-
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
80 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from .constants import Constants |
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,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from backedup import Constants | ||
|
||
import datetime | ||
import logging | ||
import os | ||
import shutil | ||
|
||
|
||
def main(): | ||
logging.basicConfig(filename='backedup.log', level=logging.INFO) | ||
create_backedup_folder() | ||
if(not did_backup_today()): | ||
backup_directory = create_backup_directory() | ||
create_backup(backup_directory) | ||
print(Constants.DONE) | ||
|
||
|
||
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) | ||
|
||
|
||
def 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,11 @@ | ||
#!/usr/bin/env python3 | ||
|
||
|
||
class Constants: | ||
DONE = "DONE!" | ||
FOLDER_EXIST = "The Backupper folder exist!" | ||
DEST_FOLDER = "/media/passport/backupper" | ||
NEW_UPDATE_FOLDER = "/backupper_" | ||
OUTPUT_FOLDER_EXIST = "An update has already occurred today!" | ||
SRC_FOLDER = "/home/chris" | ||
STARTING_UPDATE = "Starting 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