Dirtydog241

Personal blog of whatever...

Home Posts About

WWW Sync


Table of Contents

WWW Sync

Maybe you are like me and you have a couple websites you take care of and you want a more easy…. way of transfering the files with rsync from your local computer to the webserver well this script should do it. Granted you can always just type the long commands each time you need to make changes but me I hate typing anymore so the less is best.

NOTICE: You will need rsync installed on your machine and the remote server!

Debian: sudo apt install rsync

RHEL: sudo dnf install rsync

The Script

The script is simple,


#!/bin/bash
# WWWSync

PS3='Please enter your choice: '
options=("example1.com" "example2.com" "example3.com" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "example1.com")
            rsync -aHAXzP --delete -e "ssh -p 1234" /local/path/ user@remotehost:/remotepath/example1.com
            break
            ;;
        "example2.com")
            rsync -aHAXzP --delete -e "ssh -p 1234" /local/path/ user@remotehost:/remotepath/example2.com
            break
            ;;
        "example3.com")
            rsync -aHAXzP --delete -e "ssh -p 1234" /local/path/ user@remotehost:/remotepath/example3.com
            break
            ;;
        "Quit")
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done

/local/path/ is the local path the files are in on your computer, example /home/user/git/project1/

/remotepath/example3.com is the path on the remote system, example /var/www/example3.com

user@remotehost is the remote connect example billybob@123.123.123.123

just edit those lines to the paths you need and change the example#.com to a name you will understand

save the source file to something you will remember I like wwwsync.sh and make it executable chmod +x wwwsync.sh

move it to where executable files are such as /usr/bin or /usr/local/bin or use /.local/bin if you wish.

And to run it via command line just open terminal and enter wwwsync and you should see the menu options asking which site you wish to sync. This will keep an exact copy of the DIR that is on your computer on the server.

Rsync options ran:

-a -archive archive mode

-H –hard-links preserve hard links

-A -acls preserve ACLs

-X –xattrs preserve extended attributes

-z –compress compress file data during the transfer

-P same as –partial –progress

–delete delete extraneous files from dest dirs

-e specify the remote shell to use


Last update on:

Current Time

Weather

ANDERSON WEATHER