I am attempting to replicate(rsync) the etc/webmin directory from the Master VPS (VPS-1) to the Child VPS (VPS-2). However, after performing the copy, the server summary on the Child VPS still displays the IP address of the Master VPS. My goal is to retain the IP address and networking configuration of the Child VPS while only copying the Webmin configuration. I'm using Ubuntu and below is the script I am using to achieve this:
# Create a timestamp for the log file
timestamp=$(date +%Y%m%d_%H%M%S)
# Log file path
log_file="/root/sync_log_${timestamp}.log"
# Function to log messages to the log file
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$log_file"
}
# Log start of the synchronization
log "Starting synchronization..."
# Sync Webmin configuration files
log "Syncing Webmin configuration files..."
rsync -avz --delete --exclude='dns' --exclude='mail' --exclude='proc' --exclude='run' --exclude='sys' --exclude='tmp' --exclude='dev' --exclude='mnt' --exclude='var/run' --exclude='var/lock' --exclude='var/tmp' --exclude='var/log' /etc/webmin/ root@VPS-2-SERVER-IP:/etc/webmin/ >> "$log_file" 2>&1
# Dump all databases on VPS-1
log "Dumping all databases on VPS-1..."
mysqldump -u root -p'VPS-1_MYSQL_PASSWORD_FOR_USER_ROOT' --all-databases > /root/all_databases_dump.sql 2>> "$log_file"
# Copy the database dump to VPS-2
log "Copying the database dump to VPS-2..."
scp /root/all_databases_dump.sql root@VPS-2_SERVER_IP:/root/ >> "$log_file" 2>&1
# Import all databases on VPS-2 (no password needed for 'root' user)
log "Importing all databases on VPS-2..."
ssh root@VPS_2_SERVER_IP "mysql -u root -p'VPS_2_MYSQL_PASSWORD_FOR_USER_ROOT' < /root/all_databases_dump.sql" >> "$log_file" 2>&1
# Remove the local database dump file on VPS-1
log "Removing the local database dump file..."
rm /root/all_databases_dump.sql
# Log end of the synchronization
log "Synchronization completed."
# Optional: Delete old log files (older than 7 days)
# This will delete log files older than 7 days (adjust as needed)
find /root -maxdepth 1 -type f -name "sync_log_*" -mtime +7 -exec rm {} \;
# Exit with success status
exit 0```