Skip to content

Instantly share code, notes, and snippets.

@nischay876
Last active March 2, 2023 20:52
Show Gist options
  • Save nischay876/8e884d3b26d25761ab6a722730ad702f to your computer and use it in GitHub Desktop.
Save nischay876/8e884d3b26d25761ab6a722730ad702f to your computer and use it in GitHub Desktop.
Migrate Hestia Control Panel To New VPS
echo "Create Backup For all Users (Run On VPS 1)"
v-backup-users
echo "Backup Job Done"
#!/bin/bash
echo "Copy All User Backup To New VPS Via SCP (Run On VPS 1)"
# use "ssh-keygen" and add that key in VPS 2 if getting public key error
# Prompt the user for the server IP address
echo "Enter the server IP address:"
read server_ip
# Check if the IP address is valid
if ! [[ "$server_ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
echo "Invalid IP address. Please try again."
exit 1
fi
# Run the command to transfer the latest .tar files
find /backup/ -name "*.tar" -printf "%f\n" | sort -t '.' -k1,1 -k2,2nr | sort -t '.' -u -k1,1 --version-sort | xargs -I{} find /backup/ -type f -name {} -print0 | xargs -0 -I{} scp {} root@"$server_ip":/backup/
#!/bin/bash
echo "Rename All Files (Run On VPS 2)"
# Change to the directory where the files are located
cd /backup/
# Loop through all the .tar files in the directory
for file in *.tar; do
# Extract the first part of the filename before the period
new_name=$(echo "$file" | cut -d '.' -f 1).tar
# Rename the file with the new name
mv "$file" "$new_name"
done
#!/bin/bash
echo "Restore All Users (Run On VPS 2)"
# Change to the directory containing the .tar files
cd /backup
# Loop over the .tar files
for file in *.tar; do
# Extract the username from the filename (assumes the format "username.tar")
username="${file%.tar}"
# Run the v-restore-user command with the username and filename arguments
v-restore-user "$username" "$file"
sleep 0.2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment