Skip to content

Instantly share code, notes, and snippets.

@iann0036
Last active March 13, 2016 07:46
Show Gist options
  • Save iann0036/43c39ecd276c45772464 to your computer and use it in GitHub Desktop.
Save iann0036/43c39ecd276c45772464 to your computer and use it in GitHub Desktop.
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 [email protected]
ssh-copy-id [email protected]
rm -rf /etc/apache2/sites-available/
rm -rf /etc/apache2/sites-enabled/
scp -r [email protected]:/etc/postfix/ /etc/
scp -r [email protected]:/etc/apache2/httpd.conf /etc/apache2/httpd.conf
scp -r [email protected]:/etc/apache2/sites-available/ /etc/apache2/
scp -r [email protected]:/etc/apache2/sites-enabled/ /etc/apache2/
scp -r [email protected]:/etc/apache2/ssl/ /etc/apache2/
scp -r [email protected]:/etc/php5/ /etc/
scp -r [email protected]:/usr/lib/php5/ /usr/lib/
ssh [email protected] "rm -f /tmp/*.zip; cd /tmp; zip -r root.zip /root/;"
scp -r [email protected]:/tmp/root.zip /tmp/
ssh [email protected] "cd /tmp; zip -r www.zip /var/www/;"
scp -r [email protected]:/tmp/www.zip /tmp/
ssh [email protected] "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 [email protected]:/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 [email protected]:/etc/letsencrypt/ /etc/
scp -r [email protected]:/usr/local/letsencrypt/ /usr/local/
ssh [email protected] "crontab -l > /tmp/crontab;"
scp -r [email protected]:/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