Linux environment data Backup python script

Source: Internet
Author: User


#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.