#!/usr/bin/python
#Filename: backupscript.py
Import OS
Import time
# The files and directories to is backed up is specified in a list.
Source = ['/data/']
# The backup must is stored in a main backup directory
Target_dir = '/mnt/backup/'
# The current day was the name of the subdirectory in the main directory
Today = Target_dir + time.strftime ('%y_%m_%d ')
# The current time is the name of the TAR archive
now = Time.strftime ('%h_%m_%s ')
# Create The subdirectory if it isn ' t already there
If not os.path.exists (today):
Os.mkdir (today)
print ' Successfully created directory ', today
# The name of the tar file
target = today + Os.sep + Now + '. tar.gz '
# We Use the tar command (in Unix/linux) to put the files in a tar archive
Tar_command = "Tar zcvf '%s '%s"% (target, ". Join (source))
If Os.system (tar_command) = = 0:
print ' successful backup to ', target
Else
print ' Backup failed '
Search
Copy
Linux environment data Backup python script