Skip to content

Instantly share code, notes, and snippets.

@efann
Last active November 7, 2022 20:57
Show Gist options
  • Save efann/38368f6f32b24eb07163ce13e0fc4744 to your computer and use it in GitHub Desktop.
Save efann/38368f6f32b24eb07163ce13e0fc4744 to your computer and use it in GitHub Desktop.
#!/bin/bash
# License: Eclipse Public License - v 2.0 (https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html)
# Updated on November 7, 2022
#------------------------------------------------------------------------------
function backupFolder
{
lcRootBackup="$1"
lcSource="$2"
lcBackupDest="$lcRootBackup$lcSource"
if [ ! -d "$lcSource" ]
then
echo -e "\n$lcSource does not exist. Skipping. . . .\n\n"
return
fi
if [ ! -d "$lcBackupDest" ]
then
mkdir -p "$lcBackupDest"
fi
echo -e "\nCopying backup files to the archive folder, $lcBackupDest. . . .\n\n"
pushd "$lcSource"
# If password has been passed. . . .
if [ -n "$3" ]
then
# You need to install 7-zip for this to work.
# apt-get install p7zip-full p7zip-rar
lcPassword="$3"
echo -e "\nEncrypting. . . .\n"
lcZipFile="$lcBackupDest/files-in-"$(basename "$lcSource")".7z"
# If you don't remove the zip file, then 7zip with just refresh.
# And if you have changed the password, then the operation
# will fail.
if [ -f "$lcZipFile" ]
then
rm "$lcZipFile"
fi
7z a "$lcZipFile" *.* -r -p"$lcPassword" -mhe -mx9 -t7z -y
7z t "$lcZipFile" -p"$lcPassword" -y
else
cp -rv * "$lcBackupDest"
fi
popd
}
#------------------------------------------------------------------------------
PASSWORD="<password>"
BACKUP_ROOT="/backup/current/misc"
USERMAIN="<user>"
echo -e "====================================="
backupFolder "$BACKUP_ROOT" "/etc/tomcat8/Catalina/localhost" "$PASSWORD"
echo -e "====================================="
backupFolder "$BACKUP_ROOT" "/usr/local/sbin" "$PASSWORD"
echo -e "====================================="
backupFolder "$BACKUP_ROOT" "/etc/apache2/sites-available"
echo -e "====================================="
backupFolder "$BACKUP_ROOT" "/home/$USERMAIN/python" "$PASSWORD"
echo -e "====================================="
backupFolder "$BACKUP_ROOT" "/etc/postgresql/9.5/main" "$PASSWORD"
echo -e "====================================="
echo -e "Backing up cron. . . ."
crontab -l > "$BACKUP_ROOT/crontab.root"
echo -e "====================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment