Created
March 1, 2016 19:11
-
-
Save huglester/9f6d7f86a77a4e883fec to your computer and use it in GitHub Desktop.
This little bash scripts allows you to transfer DirectAdmin accounts to a new server. It first checks if the account is already backed up or installed on the new server (for security). If not existing on the new server, it starts the backup and waits for it to finish. Once finished, it will copy the backup to the new server and starts the restore.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
password="******" | |
target="127.0.0.1" | |
if [ -z "$1" ]; then | |
echo "Please give me the account to backup. "; | |
exit 0 | |
fi | |
if [ -f /home/admin/admin_backups/user.admin.$1.tar.gz ] | |
then | |
echo "Account $1 is already backed up. " | |
exit 0 | |
fi | |
if sshpass -p $password ssh root@$target stat /home/$1 \> /dev/null 2\>\&1 | |
then | |
echo "Account /home/$1 already exists on the new server. " | |
exit 0 | |
fi | |
echo "Backup up account $1. " | |
backup="echo \"action=backup&owner=admin&select%30=$1&type=admin&value=multiple&what=all&when=now&where=local&local%5Fpath=%2Fhome%2Fadmin%2Fadmin%5Fbackups\" >> | |
/usr/local/directadmin/data/task.queue" | |
eval $backup | |
while [ ! -s /home/admin/admin_backups/user.admin.$1.tar.gz ] | |
do | |
printf "." | |
sleep 1; | |
done | |
echo "" | |
echo "Backup created, copy it to new server. " | |
copy="sshpass -p $password scp /home/admin/admin_backups/user.admin.$1.tar.gz root@$target:/home/admin/admin_backups" | |
eval $copy | |
chmod="sshpass -p $password ssh root@$target 'chmod 0777 /home/admin/admin_backups/user.admin.$1.tar.gz'" | |
eval $chmod | |
echo "Copied and chmodded. " | |
restore="sshpass -p $password ssh root@$target 'echo | |
\"action=restore&ip%5Fchoice=file&local%5Fpath=%2Fhome%2Fadmin%2Fadmin%5Fbackups&owner=admin&select%30=user%2Eadmin%2E$1%2Etar%2Egz&type=admin&value=multiple&when=now&where=local\" | |
>> /usr/local/directadmin/data/task.queue'" | |
eval $restore | |
echo "Restore started. " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment