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. ...
随机推荐
- QQ列表展示
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- Hibernate Open Session In View模式【转】
来源:http://www.yybean.com/opensessioninviewfilter-role-and-configuration 一.作用 Spring为我们解决Hibernate的Se ...
- iOS Safari 中click点击事件失效的解决办法
问题起因: 在微信公众号开发(微站)过程中用jquery的live方法绑定的click事件点击无效(不能执行) 问题描述 当使用委托给一个元素添加click事件时,如果事件是委托到 document ...
- Android入门(三):使用TextView、EditText 和Button接口组件
我使用的IDE是Android Studio 2.1,虽然使用Eclipse也可以进行Android的开发,但是网上的大神大都推荐Android Studio,愿意了解的朋友可以参考知乎上关于Andr ...
- NOI2015 题解
[NOI2015]程序自动分析 离散化+并查集. [NOI2015]软件包管理器 [Noi2015]寿司晚宴 [Noi2015]荷马史诗 [NOI2015]品酒大会 [Noi2015]小园丁与老司机
- mysql错误汇总
1,mysql报Fatal error encountered during command execution的解决办法 连接字符串里加上 Allow User Variables=True 解决. ...
- comebotree树
comebotree树: java: @RequestMapping(value="/combobox.do") public @ResponseBody String combo ...
- easyUI中的form表单
首先创建form表单,并在form表单上创建id便于执行表单验证 <form id="form1"action="" method="post& ...
- __DATE__ 与 __TIME__转换为标准格式时间字符串的方法
// Example of __DATE__ string: "Jul 27 2012"// 01234567890 #define BUILD_YEAR_CH0 (__DATE_ ...
- VSCODE 插件初探
写在前面 分享一个vscode插件background(用于改变背景).点击直接跳到vscode插件开发步骤 做vscode的插件,很久就有这个想法了,但是一直因为这样,那样的事情耽误,放弃了N次.不 ...