Skip to content

Instantly share code, notes, and snippets.

@sageworksstudio
Last active June 1, 2020 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sageworksstudio/16fa836132ab32dc6baaaafc8d4cc343 to your computer and use it in GitHub Desktop.
Save sageworksstudio/16fa836132ab32dc6baaaafc8d4cc343 to your computer and use it in GitHub Desktop.
Tar backups --exclude <dir>

Creating TAR backups

Bash example

  • First create a timestamp that looks something like (YearMonthDay-Hour:Minute:Second) or (20200512-02:30:00). This will give you a unique identifier.
  • Then cd into the directory you want to back up.
  • Create a tar.bz2 (bzip2 compression) file.
  • Optionally, delet the original files.

Example:

#! /bin/bash
TIMESTAMP=$(date "+%Y%m%d-%H:%M:%S")

cd /motion

# j - bzip compress
# c - create
# f - filename
tar -jcf  archive-$TIMESTAMP.tar.bz2 /path-to/files/*

rm -r /path-to/files/*

From the desktop, using the CL

Example using bz2 compression:

tar -jcf backup.tar.gz /path/to/files/to/backup/

Note 1 If you are backing up to a connected device such as a USB drive, don't backup directly to the device itself. Backup to the mount point.

Example:

tar -jcf /mount/user/somedir/backup.tar.gz /path/to/files/to/backup/

Note 2 To exclude certain directories put exclude flags before the directory/files to backup.

Example:

tar -jcf backup.tar.gz --exclude 'node_modules' --exclude 'dir-name1' --exclude 'dir-name2' /path/to/files/to/backup/

Note 3 add the -v flag to get verbose output

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