Gebruikers van een Savvii VPS hebben de mogelijkheid om SSH toegang te krijgen. Dit kan erg handig zijn om bijvoorbeeld snel een backup te maken of een kopie te maken van een website. Voor het opzetten van een nieuwe actuele staging omgeving kun je als volgt te werken gaan:
Productie | staging
Allereerst is het handig dat productie en staging omgevingen met elkaar kunnen communiceren via SSH. Hiervoor is het handig om een nieuwe SSH key aan te maken op de productie omgeving en deze toe te voegen aan de staging omgeving.
Productie
ssh user1@user1.savviihq.com ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/pronamic_rsa eval "$(ssh-agent -s)" ssh-add ~/.ssh/pronamic_rsa
Localhost
scp user1@user1.savviihq.com:~/.ssh/pronamic_rsa.pub ~/Downloads/pronamic_rsa.pub scp ~/Downloads/pronamic_rsa.pub user2@user2.savviihq.com:~/tmp/pronamic_rsa.pub
Staging
ssh user2@user2.savviihq.com cat ~/tmp/pronamic_rsa.pub >> ~/.ssh/authorized_keys rm ~/tmp/pronamic_rsa.pub
Productie » staging
ssh user1@user1.savviihq.com cd ~/wordpress/current echo "wp-config.php" > staging-exclude.txt echo "wp-content/infinitewp/backups" >> staging-exclude.txt echo "wp-content/mu-plugins" >> staging-exclude.txt echo "wp-content/mysql" >> staging-exclude.txt echo "wp-content/uploads/2002" >> staging-exclude.txt echo "wp-content/uploads/2003" >> staging-exclude.txt echo "wp-content/uploads/2004" >> staging-exclude.txt echo "wp-content/uploads/2005" >> staging-exclude.txt echo "wp-content/uploads/2006" >> staging-exclude.txt echo "wp-content/uploads/2007" >> staging-exclude.txt echo "wp-content/uploads/2008" >> staging-exclude.txt echo "wp-content/uploads/2009" >> staging-exclude.txt echo "wp-content/uploads/2010" >> staging-exclude.txt echo "wp-content/uploads/2011" >> staging-exclude.txt echo "wp-content/uploads/2012" >> staging-exclude.txt echo "wp-content/uploads/2013" >> staging-exclude.txt echo "wp-content/uploads/2014" >> staging-exclude.txt echo "wp-content/uploads/2015" >> staging-exclude.txt echo "wp-content/uploads/backwpup*" >> staging-exclude.txt echo "wp-content/uploads/gravity_forms" >> staging-exclude.txt echo "wp-content/uploads/sites" >> staging-exclude.txt # wp db export current.sql mysqldump --user=user1 --password=******** --add-drop-table user1 > current.sql rsync -avuz --exclude-from=staging-exclude.txt . user2@user2.savviihq.com:~/wordpress/current
Het staging-exclude.txt
bestand kun je in principe eenmalig aanmaken en in bijhouden welke mappen niet mee hoeven naar de staging omgeving. In bovenstaand voorbeeld heb ik veel uploads mappen uitgesloten.
Staging omgeving
ssh user2@user2.savviihq.com cd ~/wordpress/current # wp db reset # wp db import current.sql # wp search-replace 'http://user1.savviihq.com' 'http://user2.savviihq.com' mysql --user=user2 --password=******** user2 < current.sql
WP-CLI
Helaas werkt WP-CLI momenteel niet op onze Savvii VPS’en. Hierdoor is het exporteren en importeren van de database nog wat omslachtig. Met WP-CLI zou dit vereenvoudig kunnen worden wp db export
, wp db reset
, wp db import
en wp search-replace
.
Resources
- http://www.linuxquestions.org/questions/linux-server-73/tar-using-include-file-and-exclude-file-one-liner-908800/
- http://stackoverflow.com/questions/9427553/how-to-download-a-file-from-server-using-ssh
- http://askubuntu.com/questions/4830/easiest-way-to-copy-ssh-keys-to-another-machine
- http://askubuntu.com/questions/46424/adding-ssh-keys-to-authorized-keys