-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cfa942
commit 8745392
Showing
6 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
|
||
source "$DEPLOY_SCRIPTS_FOLDER/utils/util.sh" | ||
source "$CONFIG_FOLDER/deployment" | ||
|
||
#load config | ||
DEPLOYMENT_CONFIG_FILE="$CONFIG_FOLDER/deployment.$DEPLOYENV" | ||
if [ ! -e $DEPLOYMENT_CONFIG_FILE ]; then | ||
printf "\033[0;31m Unknown Environment: $DEPLOYENV \033[0m \n" | ||
exit 1 | ||
fi | ||
|
||
source $DEPLOYMENT_CONFIG_FILE | ||
|
||
ask "Pull files from $DEPLOY_HOST ($DEPLOY_APPROOT/current/$DEPLOY_DATA_FOLDER)\nto localhost ($DEPLOY_DATA_FOLDER)?" | ||
|
||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi | ||
|
||
ask "Backup local files?" 0 | ||
|
||
if [ $? -eq 0 ]; then | ||
# backup files | ||
printf "\033[0;32m Backup files in $DEPLOY_DATA_FOLDER \033[0m \n" | ||
if [ -d "$DEPLOY_DATA_FOLDER" ]; then | ||
tar -cvzf "$DEPLOY_DATA_BACKUP_FOLDER/backup_files.tar.gz" -C "$DEPLOY_DATA_FOLDER/../" "files" | ||
rm -rf $DEPLOY_DATA_FOLDER/* | ||
fi | ||
fi | ||
|
||
ZIP_FILENAME="deployment_files.tar.gz" | ||
|
||
zip files on server | ||
printf "\033[0;32m ZIP Files on server \033[0m \n" | ||
ssh $DEPLOY_USER@$DEPLOY_HOST -p $DEPLOY_PORT "bash -s" << EOF | ||
tar -czf "$DEPLOY_APPROOT/$ZIP_FILENAME" -C "$DEPLOY_APPROOT/current/$DEPLOY_DATA_FOLDER/../" "files" | ||
EOF | ||
|
||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi | ||
|
||
printf "\033[0;32m Clean local data folder \033[0m \n" | ||
rm -rf $DEPLOY_DATA_FOLDER/* | ||
|
||
# get files | ||
printf "\033[0;32m Download files from $DEPLOY_APPROOT/current/$DEPLOY_DATA_FOLDER \033[0m \n" | ||
rsync -azP -e "ssh -p $DEPLOY_PORT" $DEPLOY_USER@$DEPLOY_HOST:"$DEPLOY_APPROOT/$ZIP_FILENAME" $ZIP_FILENAME | ||
|
||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi | ||
|
||
tar -xf $ZIP_FILENAME -C $DEPLOY_DATA_FOLDER/.. | ||
|
||
# cleanup | ||
rm -rf $ZIP_FILENAME | ||
ssh $DEPLOY_USER@$DEPLOY_HOST -p $DEPLOY_PORT "bash -s" << EOF | ||
rm -rf "$DEPLOY_APPROOT/$ZIP_FILENAME" | ||
EOF |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
source "$DEPLOY_SCRIPTS_FOLDER/utils/util.sh" | ||
source "$CONFIG_FOLDER/deployment" | ||
|
||
#load config | ||
DEPLOYMENT_CONFIG_FILE="$CONFIG_FOLDER/deployment.$DEPLOYENV" | ||
if [ ! -e $DEPLOYMENT_CONFIG_FILE ]; then | ||
printf "\033[0;31m Unknown Environment: $DEPLOYENV \033[0m \n" | ||
exit 1 | ||
fi | ||
|
||
source $DEPLOYMENT_CONFIG_FILE | ||
|
||
ask "Push files from localhost (DEPLOY_DATA_FOLDER)\nto $DEPLOY_HOST ($DEPLOY_APPROOT/current/$DEPLOY_DATA_FOLDER)?" | ||
|
||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi | ||
|
||
ask "Backup server files?" 0 | ||
|
||
if [ $? -eq 0 ]; then | ||
# backup files | ||
printf "\033[0;32m Backup files in $DEPLOY_DATA_FOLDER \033[0m \n" | ||
|
||
ssh $DEPLOY_USER@$DEPLOY_HOST -p $DEPLOY_PORT "bash -s" << EOF | ||
cd $DEPLOY_APPROOT | ||
if [ -d "current/$DEPLOY_DATA_FOLDER" ]; then | ||
tar -cvzf "current/$DEPLOY_DATA_BACKUP_FOLDER/backup_files.tar.gz" -C "current/$DEPLOY_DATA_FOLDER/../" "files" | ||
rm -rfv current/$DEPLOY_DATA_FOLDER/* | ||
else | ||
echo "Data folder does not exist. Continue." | ||
fi | ||
EOF | ||
fi | ||
|
||
ZIP_FILENAME="deployment_files.tar" | ||
|
||
printf "\033[0;32m ZIP local files \033[0m \n" | ||
tar -cf $ZIP_FILENAME -C "$DEPLOY_DATA_FOLDER/../" "files" | ||
|
||
# upload files | ||
printf "\033[0;32m Upload files to $DEPLOY_APPROOT/current/$DEPLOY_DATA_FOLDER \033[0m \n" | ||
scp -P $DEPLOY_PORT -r $ZIP_FILENAME $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_APPROOT | ||
|
||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi | ||
|
||
printf "\033[0;32m Unzip data \033[0m \n" | ||
ssh $DEPLOY_USER@$DEPLOY_HOST -p $DEPLOY_PORT "bash -s" << EOF | ||
cd $DEPLOY_APPROOT | ||
tar -xf $ZIP_FILENAME -C "current/$DEPLOY_DATA_FOLDER/.." | ||
EOF | ||
|
||
#cleanup | ||
rm -rf $ZIP_FILENAME | ||
ssh $DEPLOY_USER@$DEPLOY_HOST -p $DEPLOY_PORT "bash -s" << EOF | ||
rm -rf "$DEPLOY_APPROOT/$ZIP_FILENAME" | ||
EOF |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
#!/bin/bash | ||
|
||
ask() { | ||
DEFAULT=1 | ||
DEFAULT_TEMPLATE="(Y/N=Default)" | ||
|
||
case $2 in | ||
[0] ) DEFAULT=0; DEFAULT_TEMPLATE="(Y=Default/N)";; | ||
* ) DEFAULT=1;; | ||
esac | ||
|
||
printf "\033[0;32m$1 \033[0m \n" | ||
read -p "Answer (Y/N=Default): " yn | ||
read -p "Answer: $DEFAULT_TEMPLATE: " yn | ||
|
||
case $yn in | ||
[Yy]* ) return 0; break;; | ||
[Nn]* ) return 1; break;; | ||
* ) return 1; break;; | ||
[Yy]* ) return 0;; | ||
[Nn]* ) return 1;; | ||
* ) return $DEFAULT;; | ||
esac | ||
} |
This file contains 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