Skip to content

Instantly share code, notes, and snippets.

@hitorilabs
Last active October 14, 2023 15:02
Show Gist options
  • Save hitorilabs/82f5f09fe03258b5edd6fd38122b5cae to your computer and use it in GitHub Desktop.
Save hitorilabs/82f5f09fe03258b5edd6fd38122b5cae to your computer and use it in GitHub Desktop.
script for backing up a system, I personally ignore home because I don't keep anything important in there - I just clean install when needed. To extract the file, replace `-c` with `-x` and specify the destination (note: this will overwrite existing files)
: ${DESTINATION_DIRECTORY:=} [0/0]
: ${BACKUP_FILENAME:=$(date +%Y%m%d%H%M%S)-backup.tar.gz}
tar -czpvf $DESTINATION_DIRECTORY/$BACKUP_FILENAME \
--exclude=/proc \
--exclude=/tmp \
--exclude=/mnt \
--exclude=/dev \
--exclude=/sys \
--exclude=/run \
--exclude=/var \
--exclude=/usr \
--exclude=/home /
@hitorilabs
Copy link
Author

https://help.ubuntu.com/community/BackupYourSystem/TAR

tar - is the command that creates the archive. It is modified by each letter immediately following, each is explained below.

c - create a new backup archive.
v - verbose mode, tar will print what it's doing to the screen.
p - preserves the permissions of the files put in the archive for restoration later.
z - compress the backup file with 'gzip' to make it smaller.
f - specifies where to store the backup, backup.tar.gz is the filename used in this example. It will be stored in the current working directory, the one you set when you used the cd command.

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