{"id":5711,"date":"2024-03-16T11:50:43","date_gmt":"2024-03-16T10:50:43","guid":{"rendered":"http:\/\/rootfan.com\/?p=5711"},"modified":"2024-03-17T11:47:33","modified_gmt":"2024-03-17T10:47:33","slug":"rman-script-de-copia-de-seguridad-de-nivel-0-y-nivel-1","status":"publish","type":"post","link":"https:\/\/rootfan.com\/es\/rman-level-0-and-level-1-backup-script\/","title":{"rendered":"Script de copia de seguridad de nivel 0 y nivel 1 de RMAN"},"content":{"rendered":"<p>En este art\u00edculo le muestro c\u00f3mo hacer una copia de seguridad de su base de datos Oracle utilizando un script bash.<\/p>\n\n\n\n<p>Utilizar\u00e1 3 archivos para la copia de seguridad RMAN.<\/p>\n\n\n\n<p>Lo ejecutas as\u00ed para generar una copia de seguridad de nivel 0 para tu SID:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\" data-no-translation=\"\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.\/rman_backup.sh -d {SID} -l 0\n<\/pre><\/div>\n\n\n<p>Para la copia de seguridad de nivel 1 debes ejecutarla as\u00ed<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\" data-no-translation=\"\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.\/rman_backup.sh -d {SID} -l 1\n<\/pre><\/div>\n\n\n<!--more-->\n\n\n\n<p>Si quieres hacer una copia de seguridad de todas las bases de datos del servidor puedes ejecutar el script as\u00ed<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\" data-no-translation=\"\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.\/rman_backup.sh -d A -l 0\n<\/pre><\/div>\n\n\n<p>La copia de seguridad ir\u00e1 a la zona flash \/ recuperaci\u00f3n r\u00e1pida.<\/p>\n\n\n\n<p>Aqu\u00ed est\u00e1 el script de copia de seguridad completo.<\/p>\n\n\n\n<p>Debe nombrar este archivo como <strong>backup_level0.rman<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\" data-no-translation=\"\"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nRUN {\n    ALLOCATE CHANNEL CH1 DEVICE TYPE DISK;\n    ALLOCATE CHANNEL CH2 DEVICE TYPE DISK;\n    BACKUP tag &#039;INCR0_DB&#039; AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0 DATABASE PLUS ARCHIVELOG DELETE INPUT;\n    BACKUP CURRENT CONTROLFILE TAG &#039;INCR0_CTL&#039;;\n    BACKUP SPFILE TAG &#039;INCR0_SPFILE&#039;;\n    #DELETE NOPROMPT EXPIRED BACKUP;\n    #DELETE NOPROMPT OBSOLETE;\n    RELEASE CHANNEL CH1;\n    RELEASE CHANNEL CH2;\n}\n<\/pre><\/div>\n\n\n<p>Aqu\u00ed est\u00e1 la copia de seguridad de nivel 1, debe nombrar este archivo como <strong>backup_level1.rman<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\" data-no-translation=\"\"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nRUN {\n    ALLOCATE CHANNEL CH1 DEVICE TYPE DISK;\n    ALLOCATE CHANNEL CH2 DEVICE TYPE DISK;\n    BACKUP tag &#039;INCR_L1_DB&#039; AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 1 DATABASE PLUS ARCHIVELOG DELETE INPUT;\n    BACKUP CURRENT CONTROLFILE TAG &#039;INCR_L1_CTL&#039;;\n    BACKUP SPFILE TAG &#039;INCR_L1_SPFILE&#039;;\n    #DELETE NOPROMPT EXPIRED BACKUP;\n    #DELETE NOPROMPT OBSOLETE;\n    RELEASE CHANNEL CH1;\n    RELEASE CHANNEL CH2;\n}\n<\/pre><\/div>\n\n\n<p>Y aqu\u00ed est\u00e1 el script bash para respaldar la base de datos.<\/p>\n\n\n\n<p>Debe nombrarlo como <strong>backup_rman.sh<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code\" data-no-translation=\"\"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\n\n# This script backs up Oracle Databases using RMAN\n# The backup level (either 0 or 1) and ORACLE_SID are passed as command-line arguments\n# If -d A is specified, it backs up all databases on the server\n# If no level is provided, the script will show a warning and exit\n\n# Get script directory\nSCRIPT_DIR=&quot;$( cd &quot;$( dirname &quot;${BASH_SOURCE&#x5B;0]}&quot; )&quot; &&gt; \/dev\/null && pwd )&quot;\n\n# ORATAB location - typically \/etc\/oratab on Unix\/Linux systems\nORATAB=&quot;\/etc\/oratab&quot;\n\n# Check if any options are provided\n# If not, display usage information and exit\nif &#x5B; $# -eq 0 ]; then\n    echo &quot;Usage: $0 -d ORACLE_SID -l BACKUP_LEVEL&quot;\n    echo &quot;ORACLE_SID: The Oracle System ID (SID) or A for all databases.&quot;\n    echo &quot;BACKUP_LEVEL: The backup level, either 0 or 1.&quot;\n    exit 1\nfi\n\n# Initialize variables\nDB_SID=&quot;&quot;\nLEVEL=&quot;&quot;\n\n# Parse command-line options for Oracle SID and backup level\nwhile getopts &quot;:d:l:&quot; opt; do\n  case $opt in\n    d) DB_SID=&quot;$OPTARG&quot; ;;\n    l) LEVEL=&quot;$OPTARG&quot; ;;\n    \\?) echo &quot;Invalid option -$OPTARG&quot; &gt;&2; exit 1 ;;\n  esac\ndone\n\n# Check if a backup level has been provided\nif &#x5B; -z &quot;$LEVEL&quot; ]; then\n    echo &quot;Warning: Backup level not specified. Please provide a backup level (0 or 1).&quot;\n    exit 1\nfi\n\n# Function to perform backup\nperform_backup() {\n    local sid=$1\n    local level=$2\n\n    # Adjust log file name to include L0 or L1 based on backup level\n    local level_tag=&quot;L${level}&quot;\n    LOG_FILE=&quot;${SCRIPT_DIR}\/rman_backup_${sid}_${level_tag}_$(date &#039;+%Y%m%d_%H%M%S&#039;).log&quot;\n\n    # Set the necessary Oracle environment variables\n    ORACLE_HOME=$(grep ^$sid: $ORATAB | cut -d: -f2)\n    export ORACLE_HOME\n    export ORACLE_SID=$sid\n    export PATH=$PATH:$ORACLE_HOME\/bin\n\n    echo &quot;Backing up database ORACLE_SID=$sid at level $level&quot;\n\n    # Determine which backup command file to use\n    local cmdfile=&quot;${SCRIPT_DIR}\/backup_level${level}.rman&quot;\n\n    # Perform the backup\n    rman target \/ log=$LOG_FILE cmdfile=$cmdfile\n}\n\n# Backup all databases if -d A is specified\nif &#x5B; &quot;$DB_SID&quot; = &quot;A&quot; ]; then\n    # Read each entry in \/etc\/oratab\n    grep -v &#039;^#&#039; $ORATAB | grep -v &#039;^\\*&#039; | cut -d: -f1 | while read sid; do\n        if &#x5B; -n &quot;$sid&quot; ]; then\n            perform_backup &quot;$sid&quot; &quot;$LEVEL&quot;\n        fi\n    done\nelse\n    # Backup a single database\n    if grep -q &quot;^$DB_SID:&quot; $ORATAB; then\n        perform_backup &quot;$DB_SID&quot; &quot;$LEVEL&quot;\n    else\n        echo &quot;The Oracle SID provided does not exist in \/etc\/oratab.&quot;\n        exit 1\n    fi\nfi\n<\/pre><\/div>\n\n\n<p>Espero que esto ayude.<\/p>\n\n\n\n<p>Si tiene alguna pregunta, h\u00e1gala en los comentarios.<\/p>","protected":false},"excerpt":{"rendered":"<p>En este art\u00edculo te muestro c\u00f3mo hacer una copia de seguridad de tu base de datos Oracle usando un script bash. Utilizar\u00e1s 3 archivos para la copia de seguridad RMAN. Lo ejecutas as\u00ed para generar una copia de seguridad de nivel 0 para tu SID: Para la copia de seguridad de nivel 1 debes ejecutarlo as\u00ed<\/p>","protected":false},"author":1,"featured_media":6063,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_focus_keyword":"rman Level 0 and level 1 backup script","rank_math_title":"","rank_math_description":"Optimize your backup strategy with the RMAN level 0 and level 1 backup script.","rank_math_robots":"","rank_math_og_title":"","rank_math_og_description":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[31],"tags":[78,98,99,92,93],"class_list":["post-5711","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oracle","tag-backup","tag-level0","tag-level1","tag-rman","tag-script"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/rootfan.com\/wp-content\/uploads\/pexels-photo-172292-1.jpeg?fit=1880%2C1251&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/posts\/5711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/comments?post=5711"}],"version-history":[{"count":10,"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/posts\/5711\/revisions"}],"predecessor-version":[{"id":6067,"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/posts\/5711\/revisions\/6067"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/media\/6063"}],"wp:attachment":[{"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/media?parent=5711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/categories?post=5711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rootfan.com\/es\/wp-json\/wp\/v2\/tags?post=5711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}