输入时间参数获取rds备份集信息
1.脚本
[root@localhost tmp]# more geturl_test.py
#!/usr/bin/env python
#coding=utf- import os, json, urllib, datetime, shutil,sys
from aliyunsdkcore import client
from aliyunsdkrds.request.v20140815 import DescribeBackupsRequest
from aliyunsdkrds.request.v20140815 import DescribeBinlogFilesRequest today_time = datetime.datetime.now()
yes_time = today_time + datetime.timedelta(days = -)
remain_time=today_time + datetime.timedelta(days = -)
save_time = today_time + datetime.timedelta(days = -)
instance_id='testid'
backup_str = sys.argv[] #传入的时间格式为YYYYMMDD
backup_date = datetime.datetime.strptime(backup_str, '%Y%m%d') #转换成时间
end_backup_date=backup_date+datetime.timedelta(days = ) #开始时间加上一天 def Downfullbackupfile(db_instanceid):
startdate = datetime.datetime.strftime(backup_date,'%Y-%m-%d') + 'T00:00Z'
enddate = datetime.datetime.strftime(end_backup_date, '%Y-%m-%d') + 'T00:00Z' clt = client.AcsClient('test','test','test-test')
request = DescribeBackupsRequest.DescribeBackupsRequest()
request.set_accept_format('json')
request.set_action_name('DescribeBackups')
request.set_DBInstanceId(db_instanceid)
request.set_StartTime(startdate)
request.set_EndTime(enddate)
response = clt.do_action_with_exception(request)
#print response
result=json.loads(response)
list = result['Items']['Backup']
for i in list:
DBInstanceId = i['DBInstanceId']
BackupSize = i['BackupSize']
url = i['BackupDownloadURL']
idx_start = url.index('hins')
idx_end = url.index('tar.gz')
file = url[idx_start:idx_end + ].replace('/', '_')
pathname = '/home/oracle/backup/%s/%s' % (DBInstanceId, datetime.datetime.strftime(yes_time,'%Y%m%d'))
if (os.path.isdir(pathname) == False):
os.makedirs(pathname)
filename = '%s/%s' % (pathname, file)
#urllib.urlretrieve(url, filename)
print("%s|%s|%s"%(url ,BackupSize ,file))
return BackupSize,file def record_log(instance_id,flag,source_filesize,dest_filesize):
system_date = datetime.datetime.strftime(datetime.datetime.now(),'%Y%m%d %H:%M:%S')
backup_datetime = datetime.datetime.strftime(today_time,'%Y%m%d %H:%M:%S')
backup_date = datetime.datetime.strftime(yes_time,'%Y%m%d')
logfile="/home/oracle/scripts/backup_log/"+instance_id+".log"
fp = open(logfile, "a+")
fp.write(backup_date+"|"+instance_id+"|"+flag+"|"+backup_datetime+"|"+system_date+"|"+str(source_filesize)+"|"+str(dest_filesize)+"\n")
fp.close def check_backupfile_exist_flag(filepath):
try:
exist_flag=
for filename in os.listdir(filepath):
if filename.strip():
exist_flag=
finally:
return exist_flag def delete_file(instance_id):
savepath = '/home/oracle/backup/%s/%s' % (instance_id, datetime.datetime.strftime(save_time,'%Y%m%d'))
if (os.path.isdir(savepath)):
shutil.rmtree(savepath) def Backupdata():
instance_list = [instance_id]
for instance in instance_list:
Downfullbackupfile(instance) ##new add
def get_FileSize(filePath):
#filePath = unicode(filePath,'utf8')
fsize = os.path.getsize(filePath)
return fsize try:
if __name__ == '__main__':
#filename_dir="/home/oracle/backup/"+instance_id+"/"+datetime.datetime.strftime(yes_time,'%Y%m%d')
#remain_filename_dir="/home/oracle/backup/"+instance_id+"/"+datetime.datetime.strftime(remain_time,'%Y%m%d')
#remain_filename_exist_flag=check_backupfile_exist_flag(remain_filename_dir)
#if remain_filename_exist_flag==1:
# delete_file(instance_id) source_backupsize,source_filename=Downfullbackupfile(instance_id)
#check_dest_filename=filename_dir+"/"+source_filename
#dest_filesize=get_FileSize(check_dest_filename) #file_exist_flag=check_backupfile_exist_flag(filename_dir)
#if (file_exist_flag==1) and (dest_filesize>=source_backupsize):
# record_log(instance_id,"ok",source_backupsize,dest_filesize)
#if file_exist_flag==0:
# record_log(instance_id,"failed",source_backupsize,dest_filesize)
except Exception,e:
record_log(instance_id,"failed",,)
print 'str(Exception):\t', str(Exception)
print 'str(e):\t\t', str(e)
print 'repr(e):\t', repr(e)
print 'e.message:\t', e.message
2.调用
[root@localhost tmp]# python geturl_test.py 20190220
输入时间参数获取rds备份集信息的更多相关文章
- 深度学习原理与框架-Alexnet(迁移学习代码) 1.sys.argv[1:](控制台输入的参数获取第二个参数开始) 2.tf.split(对数据进行切分操作) 3.tf.concat(对数据进行合并操作) 4.tf.variable_scope(指定w的使用范围) 5.tf.get_variable(构造和获得参数) 6.np.load(加载.npy文件)
1. sys.argv[1:] # 在控制台进行参数的输入时,只使用第二个参数以后的数据 参数说明:控制台的输入:python test.py what, 使用sys.argv[1:],那么将获得w ...
- 一步一步写出java swing登录界面,以及输入的参数获取
经过好几天的学习,研究,接下来说说java swing,以及内嵌浏览器的方法. 一.swing是一个用于java应用程序用户界面的的开发工具包. 例如:接下来我们做个登录界面,简要说明 做之前的构想图 ...
- wget下载阿里云RDS备份集
[root@localhost tmp]# more wget.sh #!/bin/bash download_url=`python /tmp/geturl.py` echo $download_u ...
- RMAN增量备份-备份保留策略-设置备份集属性
RMAN增量备份:增量备份级别:0,1,2,3,4BACKUP DATABASE也是创建数据库的完整备份,但是这种备份不同于增量备份的0级备份.这种备份不包含增量备份的0级备份,并不支持在此基础上再创 ...
- 数据文件、日志文件、归档文件、控制文件、参数文件及RMAN备份数据库信息查询
一.查看数据库信息:=====================1.数据文件 SQL> SELECT FILE#,STATUS,ENABLED,NAME FROM V$DATAFILE; FILE ...
- python 中 使用sys模块 获取运行脚本时在命令行输入的参数
在python项目的开发的过程中, 经常需要运行各种python脚本, 有时候还需要根据不同的使用情况输入不同的参数, 如果每次都去编辑一下脚本那就太麻烦,太耗费时间了, 这时就可以使用Python自 ...
- 一步一步实现web程序信息管理系统之三----登陆业务逻辑实现(验证码功能+参数获取)
本篇紧接着上一篇文章[一步一步实现web程序信息管理系统之二----后台框架实现跳转登陆页面] 验证码功能 一般验证码功能实现方式为,前端界面访问一个url请求,后端服务代码生成一个图片流返回至浏览器 ...
- 黄聪:WordPress 多站点建站教程(五):获取子站点用户信息(通过输入站点ID号来获取该站点的所有用户)
得到站点ID为1的用户 <ul> <?php $blogusers = get_users('blog_id=1'); foreach ($blogusers as $user) { ...
- 实现php获取mp3文件元信息如播放时间歌曲作者等
最近收集到一个php获取mp3文件元信息的类,感觉比较方便.现在分享给大家! 下面是使用方式和测试方式: <?php include_once 'mp3file.class.php'; func ...
随机推荐
- 腾讯云CDB回档失败浅析
Ⅰ.先看问题 先简单介绍下cdb的回档功能,回档分为极速.快速.普通,分别对应指定表.指定库.整个实例回档. 控制台报错回档任务执行失败 提示信息:rollback table failed:SQL ...
- LeetCode 653 Two Sum IV - Input is a BST 解题报告
题目要求 Given a Binary Search Tree and a target number, return true if there exist two elements in the ...
- linux常用命令简述
新的公司,新的挑战.对于php的有点老油条来说,是一个不错的历练机会.调整自己,归零心态.永不放弃学习! 言归正传. 1.查找 find 主要用于做文件夹的查找. find hosts grep用于查 ...
- 神贴真开眼界:为什么很多人倡导重视能力和素质,但同时对学历有严格要求?——代表了上一场比赛的输赢,招聘成本很重要。如果上一场游戏失败了,尽量让自己成为当前群体的尖子。学历只是其中的一个作品而已,但学历代表了学生时代为之做出的牺牲。人群自有偏向集中性 good
对于软件工程师职位,没学历没关系,如果真觉得自己才高八斗,请在简历里附上 github项目链接或者 appstore/google play上你的作品.如果学历比别人低,那么想必是把时间和精力用在了其 ...
- mysql自动更新时间
ALTER TABLE sys_user MODIFY COLUMN update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDAT ...
- mysql 查询 最大值,最小值,第二大,第三大 一共四个值
最大值:select max(num) from table 第二大值:select max(num) from tablewhere num not in(select max(num) from ...
- mysql扩展性架构实践N库到2N 库的扩容,2变4、4变8
mysql扩展性架构实践N库到2N 库的扩容,2变4.4变8 http://geek.csdn.net/news/detail/5207058同城 沈剑 http://www.99cankao.com ...
- 配置notepad++支持golang开发
1 下载golang安装包和配置环境变量 到官网下载golang安装包,下载地址:https://golang.org/dl/,我选择的go1.7.windows-amd64.zip. 配置环境变量: ...
- java.lang.IllegalStateException: Connection pool shut down
最近使用HttpClient 4.5 使用 CloseableHttpClient 发起连接后,使用CloseableHttpResponse 接受返回结果,结果就报错了,上网查了下,有位stacko ...
- windows下gitbash中使用zip命令
参考: https://ranxing.wordpress.com/2016/12/13/add-zip-into-git-bash-on-windows/