It is very common for cPanel administrators to backup their data to a mountable folder. It could be either an NFS mount, or any other iSCSI / XFS / EXT mount – as long as it’s an external disk. To make your valuable backup data extra safe & secure, system administrators will want to unmount the backup drive as long as you are not using the backups.
As far as we know, this is not achievable with traditional cPanel backup, however this feature is obtainable using an external cPanel backup plugin like JetBackup. Besides being a very rich, secure and fast backup solution for a cPanel server, JetBackup also utilizes a “hooks system” giving you the power to run your own scripts in a pre or post JetBackup command with the ability to take action (like issuing an abort command for example).
The following is not officially supported by JetBackup, and there is no “out of the box” solution. In the following scenario, we will explain how to mount/unmount. Your actual implementation and use will likely vary from the example provided. Since we do not know your specific server setup, proceed at your own risk. We assume that you are using a “/backup” folder as a mountable drive for your backups and of course using at least JetBackup 3.3+ to backup your data.
We’ve created 14 hook points, that will execute a mount / unmount script for any JetBackup action that needs access to the backup folder – Backup, Clone, Crons, Download, Reindex, Restore & Snapshots.
For easier maintenance, we used a bash script for the mount / unmount command. Although you can do it straight forward, i.e “unmout /backup”, we wanted to use an external script so we can add some more validation, and take actions in case of error. As you can see in the screenshot above, here are the scripts we used –
The pre hook mount script ‘/ofir/scripts/mount.sh’
#!/bin/bash DESTINATION=/backup FLAG=$DESTINATION/unmounted.flag # if flag file exists, this means destnation is _unmounted_ if [ ! -f $FLAG ]; then echo "already mounted, aborting..." exit 0 fi # If mount fails for any reason by the operating systems, exit codes will go back to JetBackup and it will abort / continue according to the exit codes. mount $DESTINATION
The post hook mount script ‘/ofir/scripts/unmount.sh’
#!/bin/bash DESTINATION=/backup FLAG=$DESTINATION/unmounted.flag # Abort unmount script if there is JetBackup running jobs if [ `jetapi backup -F listBackupJobs | grep 'running: 1'` ]; then exit 0 fi # Abort unmount script if there is JetBackup clone running jobs if [ `jetapi backup -F listCloneJobs | grep 'running: 1'` ]; then exit 0 fi # Abort unmount script if there is JetBackup reindex running jobs if [ `jetapi backup -F listDestinations | grep 'running: 1'` ]; then exit 0 fi # Abort unmount script if there is any JetBackup action in the queue (download, restore etc..) for i in `jetapi backup -F listQueueItems | grep 'status:' | awk '{print $2}'`; do if [ $i -lt 100 ]; then exit 0 fi done # If flag file exists, this means destnation is already unmount, no need to take action if [ -f $FLAG ]; then exit 0 fi umount $DESTINATION
Thank you for reading ! 🙂
Tags: cPanel, JetBackup
Leave a Reply