亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python實現(xiàn)備份目錄的方法

 更新時間:2015年08月03日 12:53:28   作者:不是JS  
這篇文章主要介紹了python實現(xiàn)備份目錄的方法,實例總結(jié)了Python實現(xiàn)備份目錄的三種常用技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了python實現(xiàn)備份目錄的方法。分享給大家供大家參考。具體如下:

備份腳本1:

#!/usr/bin/python
# Filename: backup_ver1.py
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = ['/home/swaroop/byte', '/home/swaroop/bin']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that
# 2. The backup must be stored in a main backup directory
target_dir = '/mnt/e/backup/' # Remember to change this to what you will be using
# 3. The files are backed up into a zip file.
# 4. The name of the zip archive is the current date and time
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
  print 'Successful backup to', target
else:
  print 'Backup FAILED'

輸出:

$ python backup_ver1.py
Successful backup to /mnt/e/backup/20041208073244.zip

備份腳本2:

#!/usr/bin/python
# Filename: backup_ver2.py
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = ['/home/swaroop/byte', '/home/swaroop/bin']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that
# 2. The backup must be stored in a main backup directory
target_dir = '/mnt/e/backup/' # Remember to change this to what you will be using
# 3. The files are backed up into a zip file.
# 4. The current day is 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 zip 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) # make directory
  print 'Successfully created directory', today
# The name of the zip file
target = today + os.sep + now + '.zip'
# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
  print 'Successful backup to', target
else:
  print 'Backup FAILED'

輸出:

$ python backup_ver2.py
Successfully created directory /mnt/e/backup/20041208
Successful backup to /mnt/e/backup/20041208/080020.zip
$ python backup_ver2.py
Successful backup to /mnt/e/backup/20041208/080428.zip

備份腳本3:

#!/usr/bin/python
# Filename: backup_ver4.py
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = ['/home/swaroop/byte', '/home/swaroop/bin']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that
# 2. The backup must be stored in a main backup directory
target_dir = '/mnt/e/backup/' # Remember to change this to what you will be using
# 3. The files are backed up into a zip file.
# 4. The current day is 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 zip archive
now = time.strftime('%H%M%S')
# Take a comment from the user to create the name of the zip file
comment = raw_input('Enter a comment --> ')
if len(comment) == 0: # check if a comment was entered
  target = today + os.sep + now + '.zip'
else:
  target = today + os.sep + now + '_' + \
    comment.replace(' ', '_') + '.zip'
  # Notice the backslash!
# Create the subdirectory if it isn't already there
if not os.path.exists(today):
  os.mkdir(today) # make directory
  print 'Successfully created directory', today
# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
  print 'Successful backup to', target
else:
  print 'Backup FAILED'

輸出:

$ python backup_ver4.py
Enter a comment --> added new examples
Successful backup to /mnt/e/backup/20041208/082156_added_new_examples.zip
$ python backup_ver4.py
Enter a comment -->
Successful backup to /mnt/e/backup/20041208/082316.zip

希望本文所述對大家的Python程序設(shè)計有所幫助。

相關(guān)文章

  • Django集成Celery實現(xiàn)高效的異步任務(wù)處理的全過程

    Django集成Celery實現(xiàn)高效的異步任務(wù)處理的全過程

    Django?作為一個強大的?Python?Web?框架,可以通過集成?Celery?這一異步任務(wù)隊列來優(yōu)化這些任務(wù)的處理,本文將深入探討如何在?Django?項目中集成?Celery,包括?Celery?的基本配置、定義任務(wù)、以及監(jiān)控任務(wù)執(zhí)行,需要的朋友可以參考下
    2023-11-11
  • Python 文件操作的詳解及實例

    Python 文件操作的詳解及實例

    這篇文章主要介紹了Python 文件操作的詳解及實例的相關(guān)資料,希望通過本文大家能夠理解掌握Python 文件操作的知識,需要的朋友可以參考下
    2017-09-09
  • Python編程中的反模式實例分析

    Python編程中的反模式實例分析

    這篇文章主要介紹了Python編程中的反模式,詳細(xì)講述了反模式的害處并以實例形式具體分析了容易造成的易錯點,對于Python學(xué)習(xí)來說具有一定的參考借鑒價值,需要的朋友可以參考下
    2014-12-12
  • 寶塔面板成功部署Django項目流程(圖文)

    寶塔面板成功部署Django項目流程(圖文)

    這篇文章主要介紹了寶塔面板成功部署Django項目流程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • 一些Python中的二維數(shù)組的操作方法

    一些Python中的二維數(shù)組的操作方法

    這篇文章主要介紹了一些Python中的二維數(shù)組的操作方法,是Python學(xué)習(xí)當(dāng)中的基礎(chǔ)知識,需要的朋友可以參考下
    2015-05-05
  • Python與Redis的連接教程

    Python與Redis的連接教程

    這篇文章主要介紹了Python與Redis的連接教程,Redis是一個高性能的基于內(nèi)存的數(shù)據(jù)庫,需要的朋友可以參考下
    2015-04-04
  • Python heapq使用詳解及實例代碼

    Python heapq使用詳解及實例代碼

    這篇文章主要介紹了Python heapq使用詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • Python實現(xiàn)基本數(shù)據(jù)結(jié)構(gòu)中隊列的操作方法示例

    Python實現(xiàn)基本數(shù)據(jù)結(jié)構(gòu)中隊列的操作方法示例

    這篇文章主要介紹了Python實現(xiàn)基本數(shù)據(jù)結(jié)構(gòu)中隊列的操作方法,結(jié)合實例形式演示了Python針對數(shù)據(jù)結(jié)構(gòu)中隊列的初始化、插入、刪除、判斷隊列滿及隊列空等相關(guān)操作技巧,需要的朋友可以參考下
    2017-12-12
  • python操作mysql數(shù)據(jù)庫

    python操作mysql數(shù)據(jù)庫

    本篇文章主要介紹了python操作mysql數(shù)據(jù)庫的相關(guān)知識,具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • python GUI庫圖形界面開發(fā)之PyQt5布局控件QGridLayout詳細(xì)使用方法與實例

    python GUI庫圖形界面開發(fā)之PyQt5布局控件QGridLayout詳細(xì)使用方法與實例

    這篇文章主要介紹了python GUI庫圖形界面開發(fā)之PyQt5布局控件QGridLayout詳細(xì)使用方法與實例,需要的朋友可以參考下
    2020-03-03

最新評論