Created
February 21, 2019 11:58
-
-
Save erdnuesse/60cefac2238884f758d34d354f7c39e0 to your computer and use it in GitHub Desktop.
public wordpress transfer script
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 | |
# setting source vars | |
# src db user | |
srcusr='backup' | |
srcdbp="DB_PASS_FOR_USER" | |
srcdbhost='IP_ADDR_OF_SRC_DB' | |
srcdb='DB_NAME' | |
srcfolder='/var/www/html' | |
srcfilehost="IP_OF_WEBSERVER" | |
# target vars | |
tgtusr='TGT_DB_USR_NAME' | |
tgtdbp="DB_PASSWD_FOR_USER" | |
tgtdbhost='TARGET_DB_HOST_IP' | |
tgtdb='TARGET_DB_NAME' | |
tgtfolder='/var/www/html' | |
tgtowner='www-data:www-data' | |
# bkp vars | |
bkprhythm="deployment" | |
bkppath="/var/backups/website/$bkprhythm" | |
bkpfolder='/var/www/html' | |
# tmp + vars to change during transfer | |
# NEEDS EDITING IF NO CHANGE PLANNED! | |
oldwebname="\/\/EXAMPLE.OLDSERVERDOMAIN.TLD" | |
newwebname="\/\/NEWSERVERDOMAIN.com" | |
tmppath="/var/$(date +'%Y%m%d%H%M')/" | |
######## NO MORE EDITING AND MODIFICATIONS BELOW THIS LINE ####### | |
#preparing temp and backup folders | |
mkdir -p $tmppath/{files,db} | |
mkdir -p $bkppath | |
# creating deployment backups | |
echo starting backups | |
tar -cpzf $bkppath/$(date +"%Y%m%d")-web-bak.tar.gz --one-file-system $bkpfolder | |
mysqldump -u $tgtusr -p$tgtdbp -h $tgtdbhost $tgtdb --add-drop-table | gzip > $bkppath/$(date +"%Y%m%d")-web-bak.sql.gz | |
# starting deployment here... | |
# cleaning up target (optional) | |
# rm -rf /var/www/html/* | |
#fetching files | |
# rescuing the config | |
echo copytime | |
cp -rf $tgtfolder/wp-config.php /tmp/ | |
# if you're sure, then you can skip the temporary folder. | |
scp -q -i /etc/ssh/svcusr.ppk -pr svcusr@$srcfilehost:$srcfolder/. $tgtfolder/ | |
# restore the poor guy | |
cp /tmp/wp-config.php $tgtfolder/ | |
# this is with temp folder TESTING NEEDED - VARIABLES! | |
# scp -v -i /etc/ssh/svcusr.ppk -pr svcusr@TARGETSERVERIP:$bkpfolder/* /var/backups/transfer/files/ | |
#setting ownership | |
chown -R $tgtowner $tgtfolder | |
# setting file permissions | |
find $tgtfolder/ -type f -exec chmod 644 {} \; | |
find $tgtfolder/ -type d -exec chmod 755 {} \; | |
echo now the database | |
echo get it | |
# sucking db | |
mysqldump -u $srcusr -p$srcdbp -h $srcdbhost $srcdb --add-drop-table > $tmppath/$(date +"%Y%m%d")-web-pub.sql | |
# sed'ing db - ONLY IF NEEDED! | |
echo sed it | |
sed -i -e "s/$oldwebname/$newwebname/g" $tmppath/$(date +"%Y%m%d")-web-pub.sql | |
sed -i -e "s/$srcdbhost/$tgtdbhost/g" $tmppath/$(date +"%Y%m%d")-web-pub.sql | |
# pushing files to target (only if using temp folder) | |
#cp -rf /var/backups/transfer/files/* /var/www/html/ | |
# pumping database | |
echo pump it | |
mysql -u $tgtusr -p$tgtdbp -h $tgtdbhost $tgtdb < $tmppath/$(date +"%Y%m%d")-web-pub.sql | |
# dont remember what this was for... a db backup that late? | |
# mysqldump -u backup -pDBPASSWORD -h DBHOST wordpress < /var/backups/transfer/$(date +"%Y%m%d")-web-pub.sql | |
echo "finished... FIRST!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment