How to Backup a Codebase, Server Side, Well & Good
Make a Copy of an Entire Codebase:
Very useful for preparing for a major version update.
Let’s say you’ve got a codebase, living at:
/home/USERNAME/public_html/
You can make a copy of the whole gosh dern thing, while watching the files stream before your eyes with:
cp -Rv /home/USERNAME/public_html/ /home/USERNAME/public_html_YYYYMMDD_bak/
Note:
The above DOES indeed copy hidden files (whereas cp -r * may fail).
-R does NOT resolve weirdo non-existent links (trust me, you’d rather not bump into a non-resolving weirdo link in a dark alley).
-v means “verbose” so you can see what’s happening.
Also note:
Make sure that the destination dir doesn’t yet exist, else you’ll copy a copy of the source dir within the destination dir (which would be rather redundant and cyclical, wouldn’t it).
Alternatively, you can make a tar.gz of the whole gosh dern thing with:
cd /home/USERNAME/
tar -czvf public_html_YYYYMMDD.tar.gz /home/USERNAME/public_html/
-c creates a new .tar archive file.
-z gzips the archive file..
-v makes it verbose, and tells you what’s going on.
-f specifies a filename for the archive file.
Related articles