Skip to content

Instantly share code, notes, and snippets.

@Artistan
Last active February 12, 2018 03:06
Show Gist options
  • Save Artistan/9156fcc4e032f941f796d4b4878221f4 to your computer and use it in GitHub Desktop.
Save Artistan/9156fcc4e032f941f796d4b4878221f4 to your computer and use it in GitHub Desktop.
Sync Laravel
#!/bin/bash
# usage
# ./files.sh root@myserver.com apache:apache
# copy and mode the directory itself, so the . (dot) files are affected also.
# if you try to copy html/*, then the . (dot) files are not always included (depends on system)
read -p "Do you want to overrite EVERYTHING? (Y)" -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
# need to not overwrite some files on the prod server...
echo "overriting everything"
rsync -az --delete ./html "root@bin-esweb1.usi.ben:/var/www/
else
# need to not overwrite some files on the prod server...
echo "syncing new changes only. no env, sqlite, or log files";
rsync -az --delete --exclude='*.sqlite' --exclude='*.env' --exclude='*.log' ./html "root@bin-esweb1.usi.ben:/var/www/
if [[ -z "$2" ]]
then
ssh "$1" "cd /var/www/; chown -R $2 html;"
fi
#!/bin/bash
## example relavant to wordpress sync
rsync -rtuv --delete --exclude='*.sqlite' --exclude='*.env' --exclude='*/wp-content/uploads/*' root@{site...}:/var/www/html ./local/
rsync -rtuv --exclude='*.sqlite' --exclude='*.env' --exclude='*/wp-content/uploads/*' ./local/html root@{site...}:/var/www/
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR/html
git pull
# check if the hash has chnaged.
hash=`git rev-parse HEAD`
old_hash=`cat ../git.hash`
if [[ $hash != $old_hash && -z $1 ]]
then
echo 'no match'
cd ..
# sync changes to web servers
rsync -az --delete --exclude='*.sqlite' --exclude='*.env' --exclude='*.log' ./html "$1:/var/www/"
ssh "$1" "cd /var/www/; chown -R apache:apache html;"
echo $hash > git.hash
fi
@Artistan
Copy link
Author

Artistan commented Dec 7, 2017

git pull is useful if you are doing some testing and want to dev local and instantly update a remote server.
add that script as sync.sh in your /var/www directory

run watch -n5 "./sync.sh root@server.name.com"

it will try to pull every 5 seconds and if it does pull then it will rsync the html dir to another server also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment