#!/usr/bin/env Python
#-*-Coding:utf-8-*-
Import OS
Import Sys
def get_dir (path):
Print (path, ' \ n ')
return Os.listdir (PATH)
def bak_file (Path, Path_bak):
List = Os.listdir (path)
For L in list:
File_path = Os.path.join (path, L)
File_path_bak = Os.path.join (Path_bak, L)
Print
File_path
# If the file path is directory
If Os.path.isdir (File_path):
# If the folder does not exist in the backup directory, create the
If not Os.path.isdir (File_path_bak):
create_com = ' mkdir-p '%s ' \
% (File_path_bak)
If Os.system (create_com) = = 0:
Print (create_com)
Else
Print (' Create Folder failure! ', Os._exit (0))
Bak_file (File_path, File_path_bak)
Else
# If the file already exists, compare the file modification time
If Os.path.isfile (File_path_bak):
Stat_bak = Os.stat (File_path_bak)
Stat_source = Os.stat (File_path)
# Determine file modification time
If Stat_source.st_mtime <= stat_bak.st_mtime:
Continue
cp_com = ' cp '%s ' '%s ' \
% (File_path, File_path_bak)
If Os.system (cp_com) = = 0:
Print (cp_com)
Else
Print (' Create Folder failure! ', Os._exit (0))
# The file directory to back up
Path = str (raw_input (' Please enter the directory to be backed up: '))
# Backup Files Directory
Path_bak = str (raw_input (' Please enter storage directory '))
# Start Backup
Bak_file (Path, Path_bak)
Python implements an incremental backup directory