Automatic backup and FTP automatic uploading for Linux system Oracle

Source: Internet
Author: User
Tags ftp connection

* * Environment Description * *

Operating system: Centos
Environment: oracle11g
ftp:192.168.148.121 User: Dell Password: 123
Solution: Automate backup with Linux crontab-tasks

* * Detailed procedure is as follows * *


**1, complete Linux automatic backup Oracle database detailed procedure http://www.111cn.net/sys/CentOS/80724.htm

**2, creating shell files tianshanbaktoftp.sh**
{{{
(Detailed code explanation) #!/bin/sh
ftp_ip=192.168.148.121 #ftp地址
Ftp_user=dell #ftp用户名
Ftp_pass=123 #ftp密码
Ftp_backup=/oraclebackup #ftp上存放备份文件的目录, you need to first build on the FTP.
Bk_dr=/backup/oracledata/tsbak #备份文件存放路径
Db_dr=/backup/oracledata/ts #已经存在文件
Days=7 #DAYS = 7 means to delete a backup 7 days ago, that is, only the last 7 days of backup
Linux_user=root #系统用户名
Date= ' Date +%y%m%d '
Tar zcvf $BK _dr/tianshan$date.tar.gz $DB _dr
Chown-r $LINUX _user: $LINUX _user $BK _dr #更改备份数据库文件的所有者
Find $BK _dr-name "tianshan*"-type f-mtime + $DAYS-exec rm {} \; #删除7天前的备份文件 (note: {} \; There are spaces in the middle)
Deldate= ' date-d -7day +%y%m%d ' #删除ftp服务器空间7天前的备份
Ftp-i-v-n $FTP _ip << end #打开ftp服务器. 21 for FTP port <<end and final end: Term: current document here documents. Here document is a code block for a special purpose
"#它使用I/O redirection to pass a sequence of commands to an interaction program or command, such as FTP, CAT, or an ex text editor. This sentence can be understood to start with a <<end FTP connection from the beginning of the session until all commands are entered end. Of course, the name of the end can be arbitrarily taken, not necessarily end, you can take other names. 】
User $FTP _user $FTP _pass #用户名, password
Binary #设置二进制传输
CD $FTP _backup #进入ftp目录
LCD $BK _dr #列出本地目录
Mput tianshan$date.tar.gz tianshan$date.tar.gz #上传目录中的文件
Mdelete tianshan$deldate.tar.gz tianshan$deldate.tar.gz #删除ftp空间7天前的备份
Bye
End

If the manual execution of SH is not a problem, and put the crontab execution report, please delete the above note, in the implementation of the test. You can use the code directly below "" "".
"" #!/bin/sh
ftp_ip=192.168.148.121
Ftp_user=dell
Ftp_pass=123
Ftp_backup=/oraclebackup
Bk_dr=/backup/oracledata/tsbak
Db_dr=/backup/oracledata/ts
Days=7
Linux_user=root
Date= ' Date +%y%m%d '
Tar zcvf $BK _dr/tianshan$date.tar.gz $DB _dr
Chown-r $LINUX _user: $LINUX _user $BK _DR
Find $BK _dr-name "tianshan*"-type f-mtime + $DAYS-exec rm {} \;
Deldate= ' date-d -7day +%y%m%d '
Ftp-i-v-n $FTP _ip << End
User $FTP _user $FTP _pass
Binary
CD $FTP _backup
LCD $BK _dr
Mput tianshan$date.tar.gz
Mdelete tianshan$deldate.tar.gz
Bye
End

'
}}}
**3, modify file properties so that it can execute * *
{{{chmod +x/backup/oracledata/tsbak/tianshanbaktoftp.sh}}}
**4, modify/etc/crontab VI/ Etc/crontab the bottom Add * *
{{5 2 * * * * root/backup/oracledata/tsbak/tianshanbaktoftp.sh >>/backup/oracledata/tsbak /mylog.log 2>&1 #表示每天凌晨2点5分执行备份 and add corresponding logging}}}
**5, restart Crond make settings effective * *
{{service crond restart #启动}}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.