IBM i on Power Virtual Server - Taking (consistent) snapshots
Diego E. KESSELMAN
Helping Businesses Move IBM Power Workloads to the Cloud | IBM i/AIX/Linux Expert | IBM Champion 2022-2024 | "IBM i en Espa?ol" & "IBM_PowerVS_en_Espa?ol" (Telegram) Admin
What is a Snapshot?
When working with IBM i on a cloud environment we have different resources to protect our data. Snapshotting is a great idea to create a point-in-time instant copy (not a full copy) to perform a rollback in case of issues.
IBM Power Virtual Server provides a snapshot feature that takes less than 1 minute to create a recovery point for our instance.
THIS IS NOT A BACKUP, JUST A ROLLBACK CHECKPOINT!!!
This means you can only restore this snapshot data to the same instance and same volumes, but still really powerful.
If you are next to update your Operating System, install PTFs, perform a major configuration or data update, this feature could save you a huge amount of time and effort.
How does a Snapshot works?
This IBM Power Virtual Server option leverages the snapshot/flashcopy/copy-on-write feature on the storage backend. IBM Cloud uses FlashSystem storage systems for your volumes, so the time it takes this copy is a couple of seconds.
IBM i and many modern operating systems delays data writes a couple of seconds to create an asynchronous write, and improve disk performance, but when taking a copy from your disk with your system still running processes could lead to a corrupt data copy. So many databases and operating systems include "sync" and "quiesce" commands, that force the pending data in memory to be written to your disk, and suspend database writes to disk sending new update transactions to memory.
IBM i includes the command CHGASPACT to perform this operation, and make your snapshot consistent.
How can I run all these as easy as possible?
IBM Cloud provides the IBM Cloud CLI that can run most of its APIs in a scriptable way. You can learn about IBM Cloud CLI and how to set the Power IaaS plugin here:
I have created a small BASH script that connects to the IBM i using SSH, quiesces the database, sign on IBM Cloud, list the volumes in your instance, takes the snapshot, release the database and sends an email with the snapshot details.
To set this up you need:
领英推荐
The Script
Save this script as "snapshot_pvs.sh"
#!/bin/bash
###############################################
# Constants
###############################################
error=0;
errmsg="";
# IBM Cloud aacount
apikey="<APIKEY>";
Resource="<ResourceID>";
Region="<REGION>";
# SSH Service
SvrAddr="Server_Address";
UserID="<SSH_User>";
# LPAR ID
InstanceID="<PVS_InstanceID>";
SnapshotName="Snap_InstanceX-"$(date -I);
# Alert eMail
mailaccount='<Email_account>'
mailfrom='<Email_From>'
mailrcpt='Email_TO'
mailserver='smtps://<MailServer_Address>:<Port>'
echo '==================';
echo 'Quiescing Database';
echo '==================';
# Pause ASP/database activity
ssh $UserID@$SvrAddr -p 8022 "system 'CHGASPACT ASPDEV(*SYSBAS) OPTION(*FRCWRT)';system 'CHGASPACT ASPDEV(*SYSBAS) OPTION(*SUSPEND) SSPTIMO(120)'" || { error=1;errmsg="Error quiescing Db2 for i";echo $errmsg; }
if (($error == 0))
? ? then
? ? # Login process
? ? ibmcloud login --apikey $apikey -r $Region || { error=1;errmsg="Error on login process";echo $errmsg; }
fi
if (($error == 0))
? ? then
? ? # Select the resource
? ? ibmcloud pi st $Resource ||{ error=1;errmsg="Error setting the resource";echo $errmsg; }
fi
if (($error == 0))
? ? then
? ? echo '================='
? ? echo 'Starting Snapshot'
? ? echo '================='
? ? # List instance volumes to an auxiliary file
? ? ibmcloud pi inlv $InstanceID |cut? -c1-36|grep -v ID>/tmp/volume_list.lst?
? ? # Create variable with valume names
? ? vols=''
? ? while read line?
? ? ? ? do?
? ? ? ? vols=$vols$line' '
? ? done < /tmp/volume_list.lst?
? ? # Start the snapshot process
? ? rm /tmp/snapshot_result.json?
? ? ibmcloud pi snapshot-create $InstanceID --volumes "$vols" --name $SnapshotName --json> /tmp/snapshot_result.json || { error=1;errmsg="Error while taking the snapshot";echo $errmsg; }
? ? SnapshotID=$(cat /tmp/snapshot_result.json|jq .snapshotID)
? ? # Remove the double quote on this variable
? ? SnapID=${SnapshotID//'"'/''}
fi
if (($error == 0))
? ? then
? ? echo '=================================='
? ? echo 'Wait 2 minutes to get the snapshot'
? ? echo '=================================='
? ? sleep 2m
? ? echo 'Resuming database activity'
? ? echo '=================================='
? ? # Resume database activity
? ? ssh $UserID@$SvrAddr -p 8022 "system 'CHGASPACT ASPDEV(*SYSBAS) OPTION(*RESUME)'" || { error=1;errmsg="Error resuming database activity";echo $errmsg; }
fi
# Creating the notification email
echo "Sending email";
cp mail_status.txt mail_status2.txt
echo "--------------------------------------------------------------------------" >> mail_status2.txt
echo ""? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?>> mail_status2.txt
if (($error == 0))
? ? then
errmsg="Successful snapshot process"
echo $errmsg? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> mail_status2.txt
echo ""? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?>> mail_status2.txt
echo "Snapshot: "$SnapshotName? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> mail_status2.txt
echo "======================================================================" >> mail_status2.txt
ibmcloud pi snap $SnapID? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> mail_status2.txt
echo "======================================================================" >> mail_status2.txt
else
? ? if [[$errmsg -eq "" ]]
then
? ? ? ? errmsg="Error during snapshot process"? ? ? ??
? ? ? ? echo $errmsg? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? >> mail_status2.txt
? ? fi
fi
echo ""? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?>> mail_status2.txt
echo "--------------------------------------------------------------------------" >> mail_status2.txt
curl --url $mailserver --ssl-reqd --mail-from $mailfrom --mail-rcpt $mailrcpt --user $mailaccount --insecure --upload-file mail_status2.txt || { error=1;errmsg="Error sending email";echo $errmsg; }
if (($error == 0))
? ? then
? ? echo '============================='
? ? echo 'Snapshot process has finished'
? ? echo '============================='
? ? cat snapshot_pvs_finish.txt
else
? ? echo '================================='
? ? echo 'Error during the snapshot process'
? ? echo ''
? ? echo $errmsg
? ? echo '================================='
fi
This is the email header file "mail_status.txt"
From: "IBM i on PowerVS" <User@EmailServer>
To: "User Name" <email_account>
Subject: Instance Snapshot - IBM i on PowerVS
?
And this is the "snapshot_pvs_finish.txt" banner file
███████╗███╗? ?██╗ █████╗ ██████╗ ███████╗██╗? ██╗ ██████╗ ████████╗? ? ██╗? ██╗ █████╗ ███████╗? ? ███████╗██╗███╗? ?██╗██╗███████╗██╗? ██╗███████╗██████╗ ██
██╔════╝████╗? ██║██╔══██╗██╔══██╗██╔════╝██║? ██║██╔═══██╗╚══██╔══╝? ? ██║? ██║██╔══██╗██╔════╝? ? ██╔════╝██║████╗? ██║██║██╔════╝██║? ██║██╔════╝██╔══██╗██║
███████╗██╔██╗ ██║███████║██████╔╝███████╗███████║██║? ?██║? ?██║? ? ? ?███████║███████║███████╗? ? █████╗? ██║██╔██╗ ██║██║███████╗███████║█████╗? ██║? ██║██║
╚════██║██║╚██╗██║██╔══██║██╔═══╝ ╚════██║██╔══██║██║? ?██║? ?██║? ? ? ?██╔══██║██╔══██║╚════██║? ? ██╔══╝? ██║██║╚██╗██║██║╚════██║██╔══██║██╔══╝? ██║? ██║╚═╝
███████║██║ ╚████║██║? ██║██║? ? ?███████║██║? ██║╚██████╔╝? ?██║? ? ? ?██║? ██║██║? ██║███████║? ? ██║? ? ?██║██║ ╚████║██║███████║██║? ██║███████╗██████╔╝██╗
╚══════╝╚═╝? ╚═══╝╚═╝? ╚═╝╚═╝? ? ?╚══════╝╚═╝? ╚═╝ ╚═════╝? ? ╚═╝? ? ? ?╚═╝? ╚═╝╚═╝? ╚═╝╚══════╝? ? ╚═╝? ? ?╚═╝╚═╝? ╚═══╝╚═╝╚══════╝╚═╝? ╚═╝╚══════╝╚═════╝ ╚═╝
╗
Once you have all these in place we need to make the script executable
chmod +x snapshot_pvs.sh
And now we can run the script :
./snapshot_pvs.sh
You will get an email notification once the script has finished.
If you have any doubt or questions feel free to contact me on the LinkedIN chat.
Good Luck!
IBMer | Negocios Digitales | Especialista en Infraestructura de TI | Ciber Resiliencia | Transformación Digital | Soluciones de Almacenamiento | Cloud | Storage
1 年Excelente. Lo único a revisar sería los 2 minutos para hacer resume al chgaspact y los 2 minutos de sleep al hacer los snapshot por el Cloud CLI
Computer Engineer - Brand Technical Specialist- PowerVS Tech Sales SME - IBM Power System Virtual Server
1 年Gracias Diego por compartir este material, resulta sencillo entenderlo y es muy conciso.