美文网首页
找出當天備份,并傳送到其它服務器Python腳本

找出當天備份,并傳送到其它服務器Python腳本

作者: e652d1fb12eb | 来源:发表于2019-12-31 17:26 被阅读0次
  #/usr/bin/env python
  #coding:utf-8
  import os,datetime
  cur_date = datetime.datetime.now().strftime('%Y-%m-%d')
  print 'today is:',cur_date
  # os.system('mount -t cifs -o uid=oracle -o
  username=xxxxxx,password=xxxxxx //xx.xx.xx.xx/e$ /mnt')
  base_dir='/data/expdata/'
  target_dir='/data/expdata/ftp'
  target_dir_2='/mnt/server_backup/TJW-GIB/'
  file_list = os.listdir(base_dir)
  for i in file_list:
          path = os.path.join(base_dir,i)    # 拼接后,用於後面判斷目錄還是文件
          #print path
          if os.path.isfile(path):        
                  f_path = os.path.join(base_dir,i)   # 如果是文件,拼接成完整文件用於複製
                  a = i.split(".")                   
                  b = a[0].split("_")         # 截取出日期部份
                  if len(b) > 4:              # 由於備份文件分片,導致部份文件名的命名分段不同
                          c = b[4]
                  else:
                          c = b[3]
                  #print c
                  if c == cur_date:           # 判斷文件時間和當前日期是否相等
                          os.system('cp %s %s' %(f_path,target_dir))
  # upload to 10.xxx.xxx.xxx

  os.system('mount -t cifs -o uid=oracle -o
  username=xxx,password=xxx //10.xxx.xxx.xxx/e$ /mnt')
  os.chdir(target_dir)
  os.getcwd()
  os.system('cp *.* %s' %target_dir_2)
  aaa = '/mnt'
  os.system('umount %s' %aaa)

相关文章

网友评论

      本文标题:找出當天備份,并傳送到其它服務器Python腳本

      本文链接:https://www.haomeiwen.com/subject/xbcioctx.html