Using crontab in LINUX for RMAN backup Experiment

Source: Internet
Author: User
Tags time 0

In LINUX, you have written a script before using crontab to perform the RMAN backup experiment. You can run it manually. You cannot run it successfully using crontab. This afternoon, we spent two hours experimenting with the following: Note: after the script is complete, run it manually. When using crontab, pay attention to the following points: 1. You need to define the environment variables, even if the ORACLE user crontab-e is used. Source/home/oracle/. bash_profile or directly put the/home/oracle/. bash_profile content at the beginning of the backup script. 2. Pay attention to the absolute path used to call RMAN in the script. Otherwise, crontab cannot be used to run successfully. For example:/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman 3. when the log is generated as file name + date, it is date "+ % Y % m % d/% H: % M: % S" in LINUX, on UNIX, use 'date + % y % m % d '. On Windows, use % date :~ 12%, where 12 is the date, which can be changed to other required numbers. 4. TIPS: to terminate the backup script that is being executed, you can use ctrl + \ or CTRL + C to set the crontab in the backup script and LINUX. 1. The backup script format is as follows: it only uses a script to back up archived logs, which is faster and easier than full backup. [Oracle @ oel-01 ~] $ Cat archback. sh #! /Bin/sh # su-oraclesource/home/oracle /. bash_profile ######### back arch test 0704/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman log/home/oracle/rman-arch' date + % Y % m % d-% H % M '. log <EOFconnect target/; run {backup archivelog all delete inputformat'/backup/archlog/arch _ % d _ % T _ % s ';} exit 2. Set a crontab scheduled task in LINUX. It was executed at on January 1, July 4. [Oracle @ oel-01 ~] $ Crontab-e53 16 4 7 */home/oracle/archback. sh press SHIFT + ZZ to save as in VI haha. The setting is executed at on January 1, July 4. [Oracle @ oel-01 ~] $ Crontab-l53 16 4 7 */home/oracle/archback. sh [oracle @ oel-01 ~] $. 3. logs generated using the archback. sh Script: [oracle @ oel-01 ~] $ Ls-al rman-arch20130704-1653.log-rw-r -- 1 oracle oinstall 1246 Jul 4 rman-arch20130704-1653.log [oracle @ oel-01 ~] $ Cat rman-arch20130704-1653.log Recovery Manager: Release 11.2.0.1.0-Production on Thu Jul 4 16:53:01 2013 Copyright (c) 1982,200 9, Oracle and/or its affiliates. all rights reserved. RMAN> connected to target database: BYS001 (DBID = 2041679290) RMAN> 2> 3> 4> Starting backup at 04-JUL-13current log archivedusing target database control file instead of recovery catalogallocated channel: ORA_DISK _ 1 channel ORA_DISK_1: SID = 41 device type = DISKchannel ORA_DISK_1: starting archived log backup setchannel ORA_DISK_1: specifying archived log (s) in backup setinput archived log thread = 1 sequence = 19 RECID = 111 STAMP = 819910382 channel ORA_DISK_1: starting piece 1 at 04-JUL-13channel ORA_DISK_1: finished piece 1 at 04-JUL-13piece handle =/backup/archlog/arch_bys0020.20130704_119 tag = TAG20130704T165302 comm Ent = NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00: 00: 03 channel ORA_DISK_1: deleting archived log (s) archived log file name =/u01/app/oracle/archbys001/latest RECID = 111 STAMP = 819910382 Finished backup at 04-JUL-13 Starting Control File and SPFILE Autobackup at 04-JUL-13piece handle =/backup/ctl_c-2041679290-20130704-04 comment = NONEFinished Control File and SPFILE Autoba Ckup at 04-JUL-13 RMAN> Recovery Manager complete. 4. In some documents, you need to set the crontab to enter the root user and restart the CROND service. I didn't restart my experiment because CROND is running. I am enabling CROND. You can restart it without restarting it. The restart example is as follows: [oracle @ oel-01 ~] $ Su-rootPassword: [root @ oel-01 ~] # Service crond statuscrond (pid 27777) is running... [root @ oel-01 ~] # Service crond restartStopping crond: [OK] Starting crond: [OK] view cron logs: [root @ oel-01 ~] # Cd/var/log [root @ oel-01 log] # tail cronJul 4 17:01:01 oel-01 crond [28305]: (root) CMD (run-parts/etc/cron. hourly) Jul 4 17:02:50 oel-01 crontab [28313]: (oracle) begin edit (oracle) Jul 4 17:02:54 oel-01 crontab [28315]: (oracle) begin edit (oracle) jul 4 17:02:58 oel-01 crontab [28317]: (oracle) begin edit (oracle) Jul 4 17:03:11 oel-01 crontab [28317]: (oracle) REPLACE (oracle) Jul 4 17:03:11 oel-01 cr Ontab [28317]: (oracle) end edit (oracle) Jul 4 17:03:27 oel-01 crontab [28321]: (oracle) LIST (oracle) Jul 4 17:04:01 oel-01 crond [27777]: (oracle) RELOAD (cron/oracle) Jul 4 17:05:21 oel-01 crond [28396]: (CRON) STARTUP (V5.0) Jul 4 17:05:21 oel-01 crond [28396]: (CRON) @ reboot jobs will be run at computer's startup. () v. cron timing command cron/etc/cron. allow/etc/cron. deny uses the same as at-u. Only the ROOT user can perform this task.-e: Edit crontab's Work content, mainly for the user's cron design-l check crontab work content-r remove all crontab work content, meaning minute Hour Date month week instruction number range 0-59 0-23 1-31 1-12 0-7 INSTRUCTION * represents any time 0 12 *** ls/root each the execution starts at 12 o'clock a day, it indicates that the time range 0, 6 * ls is executed at or 6 without writing.-It indicates that the time range is 20 8-12 * ls 8 9 10 12 12 points in 20 minutes. run all:/n indicates a number, is the nth interval */5 *** ls, which is executed every five minutes. It can also be written as 0-59/5. Each crontab has only one file, in/var/spool/cron, it is better to use absolute paths to pay attention to the problem of uneven resource allocation, such as separating multiple commands that consume system resources at the same time, cancel unnecessary output/dev/null week and day cannot coexist If the cron is not set by yourself, pay attention to system security.

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.