<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic MDS cloud backup script for R81.20 (from R82 native supported) in Scripts</title>
    <link>https://community.checkpoint.com/t5/Scripts/MDS-cloud-backup-script-for-R81-20-from-R82-native-supported/m-p/235687#M1174</link>
    <description>&lt;P&gt;Hello Checkpoint fans,&lt;BR /&gt;&lt;BR /&gt;I had to design a script to take a backup of the mds every day. I had to uploaded to Azure.&lt;BR /&gt;If you have suggestions or questions, let me now.&lt;BR /&gt;&lt;BR /&gt;16-12-2024&lt;BR /&gt;Edit the file delete after one day modified.&lt;/P&gt;
&lt;P&gt;Here it is:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#!/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" &amp;lt;&amp;lt; 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&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MobaXterm_5E9fYUSniM.png" style="width: 400px;"&gt;&lt;img src="https://community.checkpoint.com/t5/image/serverpage/image-id/28831i409D6EF12FF5D1AC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MobaXterm_5E9fYUSniM.png" alt="MobaXterm_5E9fYUSniM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the attachments for information. Thanks to &lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/181"&gt;@_Val_&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/7"&gt;@PhoneBoy&lt;/a&gt;&amp;nbsp;for my first post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 15 Feb 2026 11:31:29 GMT</pubDate>
    <dc:creator>itguru1989</dc:creator>
    <dc:date>2026-02-15T11:31:29Z</dc:date>
    <item>
      <title>MDS cloud backup script for R81.20 (from R82 native supported)</title>
      <link>https://community.checkpoint.com/t5/Scripts/MDS-cloud-backup-script-for-R81-20-from-R82-native-supported/m-p/235687#M1174</link>
      <description>4</description>
      <pubDate>Sun, 15 Feb 2026 11:31:29 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/MDS-cloud-backup-script-for-R81-20-from-R82-native-supported/m-p/235687#M1174</guid>
      <dc:creator>itguru1989</dc:creator>
      <dc:date>2026-02-15T11:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Mulit Domain Server backup script (make it myself to Azure storage account)</title>
      <link>https://community.checkpoint.com/t5/Scripts/MDS-cloud-backup-script-for-R81-20-from-R82-native-supported/m-p/235736#M1175</link>
      <description>&lt;P&gt;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/181"&gt;@_Val_&lt;/a&gt;&amp;nbsp;possible Toolbox submission.&lt;BR /&gt;Also note that in R82, the native backup tools also support S3/Azure Buckets.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 21:44:34 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/MDS-cloud-backup-script-for-R81-20-from-R82-native-supported/m-p/235736#M1175</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2024-12-13T21:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Mulit Domain Server backup script (make it myself to Azure storage account)</title>
      <link>https://community.checkpoint.com/t5/Scripts/MDS-cloud-backup-script-for-R81-20-from-R82-native-supported/m-p/235762#M1176</link>
      <description>&lt;P&gt;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/7"&gt;@PhoneBoy&lt;/a&gt;&amp;nbsp;Already working with the poster&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2024 10:50:18 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/MDS-cloud-backup-script-for-R81-20-from-R82-native-supported/m-p/235762#M1176</guid>
      <dc:creator>_Val_</dc:creator>
      <dc:date>2024-12-14T10:50:18Z</dc:date>
    </item>
  </channel>
</rss>

