Mounting/Unmounting Network Shares Before or After Backup
Note: While most of the information in this article is valid regardless of which version of CloudBerry Backup is used, the most important part (the -preAction and -postAction options) are only available since Backup for Linux v 2.9
The case described in this article is:
- There is a domain shared folder that serves as a file share
- This shared folder is used for backup (whether as the source or the destination, does not matter)
- The backup will be performed by CloudBerry Backup for Linux
Also, the commands syntax may differ for various Linux distributions and/or SMB configurations (in case it's a Linux-based NAS device). This article is based on Ubuntu 18 and a Windows 2012R2 domain network share.
So, let's start.
0. Change the backup plan ownership to the user who is allowed to mount network shares
sudo chown root:root /opt/local/CloudBerry\ Backup/etc/plans/*
Note: If you choose to use another user:group, make sure to set the same user:group in step 2
Note: For macOS it should be root:wheel instead - the same is correct for all usage of root:root
1. Create the file with the access credentials to the network share
echo "username=USERNAME" > /path/to/credentials-file
echo "password=PASSWORD" >> /path/to/credentials-file
echo "domain=DOMAIN" >> /path/to/credentials-file
Note: No need to escape any special symbols in your password with the backslash
Note: The third line is not required for a workgroup shared folder or a Linux-based NAS device
2. Assign the desirable access permission to the credentials file
chown root:root /path/to/credentials-file
chmod 600 /path/to/credentials-file
3. Add the mount point to /etc/fstab
sudo echo "//SHARE-DOMAIN-NAME/SHARED-FOLDER-PATH /mnt/SHARE cifs credentials=/path/to/credentials-file,iocharset=utf8,sec=ntlmssp 0 0" >> /etc/fstab
4. Create a script to mount the share
echo "#!/bin/bash" > /path/to/script-mount.sh
echo "mount /mnt/SHARE" >> /path/to/script-mount.sh
echo "exit 0" >> /path/to/script-mount.sh
chmod 711 /path/to/script-mount.sh
5. Create a script to unmount the share
echo "#!/bin/bash" > /path/to/script-umount.sh
echo "umount /mnt/SHARE" >> /path/to/script-umount.sh
echo "exit 0" >> /path/to/script-umount.sh
chmod 711 /path/to/script-umount.sh
6. Set the two scripts as the pre-backup action and the post-backup action
/opt/local/CloudBerry\ Backup/bin/cbb editBackupPlan -n "Backup plan name goes here" -preAction yes -preActionPath "/path/to/script-mount.sh" -postAction yes -postActionPath "/path/to/script-umount.sh -postActionRunAnyway yes"
This can be also done in the GUI or in the Web Interface, on the corresponding step of the backup plan wizard - the procedure is quite obvious so no additional description here.
Contact Us
- Tech questions
- Sales questions: sales@msp360.com