How I update my website
For a long time I would use FTP to update my website. A few years ago, I came across a post (I can't find it any longer) that taught me how to use rsync
to upload my local site to my server. I've used this ever since and have found it incredibly helpful.
The one-liner command by itself:
rsync -avP $(pwd)/ elliott@192.168.1.1:/var/www/elliott.computer/camera/ --exclude={'.DS_Store','.vscode','.nova','deploy.sh','_archive','_drafts','.gitignore','.git','**/.git'} --chmod=Du=rwx,Dgo=rx,Fu=rw,Fog=r --delete
A breakdown of this command:
-avP
→ preserves file attributes, with verbose output and a progress bar
$(pwd)/
→ run rsync from the current directory
elliott
→ SSH username
192.168.1.1
→ your server's IP address
--exclude={'.DS_Store','.vscode','.nova','deploy.sh','_archive','_drafts','.gitignore','.git','**/.git'}
→ a useful flag to exclude directories and files from the upload
--chmod=Du=rwx,Dgo=rx,Fu=rw,Fog=r
→ give everything the correct permissions
--delete
→ remove files that were removed locally
--dry-run
→ useful for testing the upload before actually running it for real
Recently I've begun to save this in a executable deploy.sh
file so that I can run it be typing ./deploy.sh
The deploy.sh file looks like this:
#!/bin/bash
rsync -avP $(pwd)/ elliott@192.168.1.1:/var/www/elliott.computer/camera/ --exclude={'.DS_Store','.vscode','.nova','deploy.sh','_archive','_drafts','.gitignore','.git','**/.git'} --chmod=Du=rwx,Dgo=rx,Fu=rw,Fog=r --delete
Run this to make the script executable:
chmod +x deploy.sh