Move SAP Hana DB from Hana server to NAS
#!/bin/bash
# Configuration
NAS_IP="192.168.0.0" #Edit the NAS IP
NAS_SHARE="NAS allocated path for backup"
MOUNT_POINT="/mnt/test" # Create directory under the mnt directory
BACKUP_DIR="/home/tinesh/sourcedb" # HANA DB Shared path
LOG_FILE="/var/log/backup_to_nas.log" # log file path
# Task to Create log file if it doesn't exist
touch "$LOG_FILE"
log_message() {
echo "$(date) - $1" | tee -a "$LOG_FILE"
}
log_message "==== Starting Backup Transfer ===="
# Function to mount NAS
mount_nas() {
if mount | grep -q "$MOUNT_POINT"; then
log_message "NAS is already mounted at $MOUNT_POINT"
else
log_message "Mounting NAS ..."
sudo mount -t cifs //"$NAS_IP"/"$NAS_SHARE" "$MOUNT_POINT" -o guest,vers=3.0
if [ $? -ne 0 ]; then
log_message "Error: Failed to mount NAS share!"
exit 1
fi
fi
}
# Task to move backup files
move_files() {
if [ -d "$BACKUP_DIR" ] && [ "$(ls -A "$BACKUP_DIR")" ]; then
log_message "Moving backup files from $BACKUP_DIR to $MOUNT_POINT..."
mv "$BACKUP_DIR"/* "$MOUNT_POINT"/
if [ $? -eq 0 ]; then
log_message "Backup transfer successful!"
else
log_message "Error: Failed to move backup files!"
exit 1
fi
else
log_message "No files found in $BACKUP_DIR to move."
fi
}
# Task to unmount NAS share
unmount_nas() {
log_message "Unmounting NAS..."
sudo umount "$MOUNT_POINT"
if [ $? -eq 0 ]; then
log_message "NAS unmounted successfully."
else
log_message "Warning: Failed to unmount NAS."
fi
}
# Trigger functions
mount_nas
move_files
unmount_nas
log_message "==== Backup Transfer Completed ===="
exit 0
#### Note: Please do multiple testing in the test Environament before execting in Live Environament ####
Disclaim : i am not responsible for if any data lose - so test multiple time and execute it
Comments
Post a Comment