#!/usr/bin/python
#Filename:backupscript.py
import os
import time

# The files and directories to be backed up are specified in a list.
source = ['/data/']

# The backup must be stored in a main backup directory
target_dir = '/mnt/backup/'

# 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 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'

搜索

复制

Linux环境数据备份Python脚本的更多相关文章

  1. Linux 环境下安装python相关

    目录 Linux 环境下安装python相关 linux软件包管理工具之yum工具(如同pip3工具) yum源理解 下载阿里云的.repo仓库文件 ,放到/etc/yum.repos.d/ yum安 ...

  2. Linux服务器数据备份恢复策略

    一.Linux 备份恢复基础 1.什么是备份 最简单的讲,备份数据的过程就是拷贝重要的数据到其他的介质之上(通常是可移动的),以保证在原始数据丢失的情况下可以恢复数据.一次备份可能是简单的 cp命令, ...

  3. 尚学python课程---11、linux环境下安装python注意

    尚学python课程---11.linux环境下安装python注意 一.总结 一句话总结: 准备安装依赖包:zlib.openssl:yum install zlib* openssl*:pytho ...

  4. 尚学linux课程---10、linux环境下安装python

    尚学linux课程---10.linux环境下安装python 一.总结 一句话总结: 直接在官网下载python的源码包即可,然后在linux下安装 linux下安装软件优先想到的的确是yum,但是 ...

  5. linux 中定时执行python脚本

    一.让Python随Linux开机自动运行 准备好要自启的脚本auto.py 用root权限编辑以下文件 sudo vim /ect/rc.local 在exit 0上面编辑启动脚本的命令(编辑rc. ...

  6. linux环境下安装python 3

    说明: 在linux环境下,都默认安装python 2的环境,由于python3在python2的基础上升级较大,所以安装python 3环境用于使用最新的python 3的语法. 安装过程: 1.下 ...

  7. linux 下后台运行python脚本

    这两天要在服务器端一直运行一个Python脚本,当然就想到了在命令后面加&符号 $ python /data/python/server.py >python.log &说明:  ...

  8. 关于linux上部署定时python脚本

    遇到的坑: Python脚本中的文件操作,最好都用绝对路径, 文件头上写 #!/usr/local/bin/python3.6 ----------------------------------- ...

  9. linux环境下安装python

    在linux系统中安装python解释器 打开官网www.python.org 选择合适的版本进行下载 将下载好的压缩包拖入Xshell中,依次输入一下命令即可 tar xf Python-.tar. ...

随机推荐

  1. 同一台机子上用多个git 账号

    Step 1 - Create a New SSH Key We need to generate a unique SSH key for our second GitHub account. 1 ...

  2. Spring+SpringMvc+Mybatis整合注意事项

    1.web.xml代码如下 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi ...

  3. Leetcode Edit Distance

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  4. 【Redis】简介与安装

    Linux 安装 [root@redis ~]# wget http://download.redis.io/releases/redis-2.8.19.tar.gz 解压缩redis[root@ha ...

  5. crawler4j 学习(二)

    crawler4j 学习(二) 实现控制器类以制定抓取的种子(seed).中间数据存储的文件夹.并发线程的数目: public class Controller { public static voi ...

  6. 一些简单编程练习题P【持续更新】

    Q1.写程序将“Hello World”打印到屏幕. A1. public class Test { public static void main(String[] args) { System.o ...

  7. 02.JavaScript基础下

    运算符 算术:+ 加.- 减.* 乘./ 除.% 取模 实例:隔行变色.秒转时间 赋值:=.+=.-=.*=./=.%= 关系:<.>.<=.>=.==.===.!=(不等). ...

  8. 使用TouchScript做2D按钮实现长按功能

    导入TouchScript 下载地址:https://www.assetstore.unity3d.com/#/content/7394 把TouchScript和Touch Debugger两个预设 ...

  9. Tomcat启动后,从spring容器中获取Bean和ServletContext

    public static Object getBean(String beanName){ ApplicationContext context = ContextLoader.getCurrent ...

  10. php上传大文件,提示出错