Hello Checkpoint fans,
I had to design a script to take a backup of the mds every day. I had to uploaded to Azure.
If you have suggestions or questions, let me now.
16-12-2024
Edit the file delete after one day modified.
Here it is:
#!/bin/bash
source /etc/profile.d/CP.sh
source $MDSDIR/scripts/MDSprofile.sh
source $MDS_SYSTEM/shared/mds_environment_utils.sh
source $MDS_SYSTEM/shared/sh_utilities.sh
source /opt/CPshrd-R81.20/tmp/.CPprofile.sh
# Script to automate MDS backup on a Check Point Multi-Domain Server
# Author: itguy1989
# Date: 16-12-2024
# Delete older files, otherwise your disk will be full
# Directory to search for .tgz files (modify as needed)
TARGET_DIR="/directory"
# Modify permissions to allow write and delete (e.g., 777 for full permissions)
chmod -R 777 "$TARGET_DIR"
# Find and delete .tgz files modified more than 1 day ago
find "$TARGET_DIR" -type f -name "*.tgz" -mtime +1 -exec rm -f {} \;
# Optional: Print confirmation
echo "Permissions modified and .tgz files modified more than 1 day ago deleted."
# Variables
DATE=$(date +"%Y-%m-%d_%H-%M-%S") # Timestamp for the backup file
RETENTION_DAYS=7 # Number of days to keep backups
BACKUP_DIR1="/backup" # backup directory
BACKUP_DIR="/backup/mds_backup_$DATE" # Directory where backups will be stored
# Check if script is run as root
if [[ $EUID -ne 0 ]]; then
echo "ERROR: This script must be run as root."
exit 1
fi
# Ensure the backup directory exists
if [[ ! -d "$BACKUP_DIR" ]]; then
echo "Backup directory $BACKUP_DIR does not exist. Creating it."
mkdir -p "$BACKUP_DIR"
if [[ $? -ne 0 ]]; then
echo "ERROR: Failed to create backup directory."
exit 1
fi
fi
# Run mds_backup
echo "Starting MDS backup..."
BACKUP_FILE="$BACKUP_DIR"
mds_backup -b -d "$BACKUP_FILE" -l -x
if [[ $? -ne 0 ]]; then
echo "ERROR: mds_backup command failed."
exit 1
fi
echo "Backup completed successfully: $BACKUP_FILE"
# Set the directory and output file name
DIR_TO_COMPRESS="$BACKUP_DIR"
OUTPUT_FILE="$BACKUP_DIR1/mds_backup_$DATE.tgz"
# Create a tarball (.tgz)
tar -czvf "$OUTPUT_FILE" -C "$DIR_TO_COMPRESS" .
# Set the permissions to allow write and delete for the user
chmod 600 "$OUTPUT_FILE"
# Print confirmation
echo "Directory compressed successfully to $OUTPUT_FILE"
# Define the directory you want to delete
DIR_TO_DELETE="$BACKUP_DIR"
# Check if the directory exists
if [ -d "$DIR_TO_DELETE" ]; then
# Delete the directory and all its contents
rm -rf "$DIR_TO_DELETE"
echo "Directory '$DIR_TO_DELETE' has been deleted."
else
echo "Directory '$DIR_TO_DELETE' does not exist."
fi
# Variables
SFTP_SERVER="10.0.0.0" # Target SFTP server hostname or IP
SFTP_USER="username" # SFTP username
SSH_KEY_PATH="/home/admin/.ssh/" # Path to the private SSH key
LOCAL_FILE_PATH="$OUTPUT_FILE" # Path to the local file you want to upload
REMOTE_DIR="/" # Remote directory where the file will be uploaded
# Ensure that the private key has proper permissions
chmod 600 "$SSH_KEY_PATH"
# Check if SSH key file exists
if [ ! -f "$SSH_KEY_PATH" ]; then
echo "Error: SSH key file not found at $SSH_KEY_PATH"
exit 1
fi
# Upload file using SFTP
sftp -i "$SSH_KEY_PATH" -o StrictHostKeyChecking=no "$SFTP_USER"@"$SFTP_SERVER" << EOF
cd "$REMOTE_DIR"
put "$LOCAL_FILE_PATH"
exit
EOF
# Check if the upload was successful
if [ $? -eq 0 ]; then
echo "File uploaded successfully."
else
echo "Error: File upload failed."
exit 1
fi
echo "MDS backup script completed."
exit 0
See the attachments for information. Thanks to @_Val_ and @PhoneBoy for my first post.