Linux环境数据备份Python脚本
#!/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脚本的更多相关文章
- Linux 环境下安装python相关
目录 Linux 环境下安装python相关 linux软件包管理工具之yum工具(如同pip3工具) yum源理解 下载阿里云的.repo仓库文件 ,放到/etc/yum.repos.d/ yum安 ...
- Linux服务器数据备份恢复策略
一.Linux 备份恢复基础 1.什么是备份 最简单的讲,备份数据的过程就是拷贝重要的数据到其他的介质之上(通常是可移动的),以保证在原始数据丢失的情况下可以恢复数据.一次备份可能是简单的 cp命令, ...
- 尚学python课程---11、linux环境下安装python注意
尚学python课程---11.linux环境下安装python注意 一.总结 一句话总结: 准备安装依赖包:zlib.openssl:yum install zlib* openssl*:pytho ...
- 尚学linux课程---10、linux环境下安装python
尚学linux课程---10.linux环境下安装python 一.总结 一句话总结: 直接在官网下载python的源码包即可,然后在linux下安装 linux下安装软件优先想到的的确是yum,但是 ...
- linux 中定时执行python脚本
一.让Python随Linux开机自动运行 准备好要自启的脚本auto.py 用root权限编辑以下文件 sudo vim /ect/rc.local 在exit 0上面编辑启动脚本的命令(编辑rc. ...
- linux环境下安装python 3
说明: 在linux环境下,都默认安装python 2的环境,由于python3在python2的基础上升级较大,所以安装python 3环境用于使用最新的python 3的语法. 安装过程: 1.下 ...
- linux 下后台运行python脚本
这两天要在服务器端一直运行一个Python脚本,当然就想到了在命令后面加&符号 $ python /data/python/server.py >python.log &说明: ...
- 关于linux上部署定时python脚本
遇到的坑: Python脚本中的文件操作,最好都用绝对路径, 文件头上写 #!/usr/local/bin/python3.6 ----------------------------------- ...
- linux环境下安装python
在linux系统中安装python解释器 打开官网www.python.org 选择合适的版本进行下载 将下载好的压缩包拖入Xshell中,依次输入一下命令即可 tar xf Python-.tar. ...
随机推荐
- python 线程之 threading(二)
在http://www.cnblogs.com/someoneHan/p/6204640.html 线程一中对threading线程的开启调用做了简单的介绍 1 在线程开始之后,线程开始独立的运行直到 ...
- 读取properties文件以及properties的用法
package cn.util; import java.io.IOException; import java.io.InputStream; import java.util.Properties ...
- <!DOCTYPE html PUBLIC 导致js代码不可用
在有了这个 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- 利用轮播原理结合hammer.js实现简洁的滑屏功能
最近有个任务,做一个非常小的h5的应用,只有2屏,需要做横向的全屏滑动切换和一些简单的动画效果,之前做这种东西用的是fullpage.js和jquery,性能不是很好,于是就想自己动手弄一个简单的东西 ...
- .net core 基本概念
asp.net core 是基于 .net core的,所以能够跨平台. 目前存在.NET Framework (CLR), .NET Core (CoreCLR) or Mono,可根据项目的具体情 ...
- ZeroMQ接口函数之 :zmq_bind - 绑定一个socket
ZeroMQ 官方地址 : http://api.zeromq.org/4-0:zmq-bind zmq_bind(3) ZMQ Manual - ZMQ/3.2.5 Name zmq_bind - ...
- java.lang.NoClassDefFoundError: javax/el/ELResolver 问题解决
HTTP Status 500 - java.lang.NoClassDefFoundError: javax/el/ELResolver type Exception report message ...
- php 开启socket配置
我在Windows命令行输入命令:C:\wamp\bin\php\php5.2.6\php.exe getXml.php以执行php文件. 出现错误:Fatal error: Call to unde ...
- centos7 最小化安装没有ifconfig及修改网卡名enoxxx为ethX
问题: 1.最小化安装centos7后发现无ifconfig命令 想通过ifconfig查看ip地址发现ifconfig命令不存在,可通过命令 #ip addr //查看ip 或者 解决: ...
- jqgrid no url reset
如果发现 jqgrid 在运行中出现次错误,可能是以下原因 $('#@(ViewBag.tabcid + "_grid")').jqGrid('navGrid', '#@(View ...