Skip to content

Instantly share code, notes, and snippets.

@iann0036
Last active Mar 13, 2016
Embed
What would you like to do?
VPS Migration Script (personalized)
#!/bin/bash
echo -n "Enter your MySQL root password, followed by [ENTER]: "
read mysqlrootpwd
echo -n "Enter your remote hosts root password, followed by [ENTER]: "
read remoterootpwd
apt-get -y update;
apt-get -y upgrade;
apt-get -y install sshpass;
apt-get -y install openssh-server ssh apache2 mysql-server php5 phpmyadmin postfix rsync gzip zip unzip screen nodejs php-pear php5-curl htop php-gettext;
cat /dev/zero | ssh-keygen -q -N ""
echo $remoterootpwd > /tmp/rootpass.txt
sshpass -f /tmp/rootpass.txt ssh-copy-id root@ian.mn
ssh-copy-id root@ian.mn
rm -rf /etc/apache2/sites-available/
rm -rf /etc/apache2/sites-enabled/
scp -r root@ian.mn:/etc/postfix/ /etc/
scp -r root@ian.mn:/etc/apache2/httpd.conf /etc/apache2/httpd.conf
scp -r root@ian.mn:/etc/apache2/sites-available/ /etc/apache2/
scp -r root@ian.mn:/etc/apache2/sites-enabled/ /etc/apache2/
scp -r root@ian.mn:/etc/apache2/ssl/ /etc/apache2/
scp -r root@ian.mn:/etc/php5/ /etc/
scp -r root@ian.mn:/usr/lib/php5/ /usr/lib/
ssh root@ian.mn "rm -f /tmp/*.zip; cd /tmp; zip -r root.zip /root/;"
scp -r root@ian.mn:/tmp/root.zip /tmp/
ssh root@ian.mn "cd /tmp; zip -r www.zip /var/www/;"
scp -r root@ian.mn:/tmp/www.zip /tmp/
ssh root@ian.mn "cd /tmp; rm -f /tmp/sqldump*; mysqldump -uroot -p${mysqlrootpwd} --single-transaction --routines --triggers --all-databases > /tmp/sqldump.sql; gzip /tmp/sqldump.sql;"
scp -r root@ian.mn:/tmp/sqldump.sql.gz /tmp/
cd /tmp
gunzip -f /tmp/sqldump.sql.gz
mysql -uroot -p${mysqlrootpwd} < /tmp/sqldump.sql
rm -rf /root/
mv /tmp/root/ /
rm -rf /var/www/
mv /tmp/var/www/ /var/
a2enmod ssl
a2enmod proxy
a2enmod proxy_http
a2enmod cgi
a2enmod ldap
a2enmod rewrite
scp -r root@ian.mn:/etc/letsencrypt/ /etc/
scp -r root@ian.mn:/usr/local/letsencrypt/ /usr/local/
ssh root@ian.mn "crontab -l > /tmp/crontab;"
scp -r root@ian.mn:/tmp/crontab /tmp/
crontab /tmp/crontab
chown -R www-data: /var/www/
sed -i 's/AllowOverride None/AllowOverride all/g' /etc/apache2/apache2.conf
sed -i 's/Options FollowSymLinks/Options +FollowSymLinks -Indexes/g' /etc/apache2/apache2.conf
echo "StartServers 1
MinSpareServers 1
MaxSpareServers 5
ServerLimit 16
MaxClients 16
MaxRequestsPerChild 0
ListenBacklog 100
" >> /etc/apache2/apache2.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment