Was looking for a way to tar backup a directory on my webserver.

Here is the command:

See Hotdealr.com for more hot deals...
See HowIFixedIt.com/hotdeals for more hot deals...

tar -cvzf /directory/where/you/want/the/backup/to/go/filename.$(date +%Y-%m-%d).tgz /directoy/you/want/to/tar

Here is what this command is doing:

  • c — to create a tar file, writing the file starts at the beginning.
  • f — specifies the filename (which follows the f) used to tar into or to tar out from
  • z — use zip/gzip to compress the tar file or to read from a compressed tar file.
  • v — verbose output, show, e.g., during create or extract, the files being stored into or restored from the tar file.

/directory/where/you/want/the/backup/to/go/ is the directory the tar file will reside after the command is run.

filename.$(date +%Y-%m-%d).tgz is the filename of the file you just archived.  It will append the year, month, and day to the file So your file will look like this: filename.2010-03-05.tgz

/directoy/you/want/to/tar is the directory including all sub directories that will be archived.

To see more info about tar run “man tar” in your terminal.