Unix tar command

Advanced feature discussion, beta programs and unsupported "Labs" features.
3 posts Page 1 of 1
by scotts » Sat Feb 08, 2020 12:12 pm
Scott,

I've done this before, please refresh my memory.

What's the best way to create an archive (backup) file in my home directory of everything I have on Sonic?

The tar command has so many switches.

I simply want to create a backup of all my files and directories.

Currently have a file called "backup.tar.gz" created in 2000.

Would like to create a new backup tar file in 2020 of everything since the 2000 backup.

And what is the command to restore a tar backup file?

What is the best way to back up everything in the shell directory?


Thanks,
by kgc » Mon Feb 10, 2020 11:10 am
tar -czf backup-filename.tar.gz files-or-directories-to-backup
Kelsey Cummings
System Architect, Sonic.net, Inc.
by scott » Wed Feb 12, 2020 11:59 am
scotts wrote:Scott,

I've done this before, please refresh my memory.

What's the best way to create an archive (backup) file in my home directory of everything I have on Sonic?

The tar command has so many switches.

I simply want to create a backup of all my files and directories.

Currently have a file called "backup.tar.gz" created in 2000.

Would like to create a new backup tar file in 2020 of everything since the 2000 backup.

And what is the command to restore a tar backup file?

What is the best way to back up everything in the shell directory?


Thanks,
Hi Scott S.,

Creating the tar file is just as kgc said in his post. However, if you've backing up your home directory, it seems like a bad idea to write the tar file _to_ your home directory initially. So write it to /tmp/yourtarfile.tar.gz, then mv it back to your home directory after you've finished. (Don't leave it in /tmp, as those files could be removed at any time.)

To restore, you use the 'x' switch to tar, so it would be: cd place_to_restore_to ; tar -xf foo.tar.gz

(Note that modern tar will auto-sense compression, so you don't have to give it a special switch to decompress.)

As far as making an incremental backup goes, I'm going to need to refer to the man page, hang on a sec...

Okay, it's a long option, "--newer-mtime=DATE"

Where for "DATE" you can supply a filename path starting with "/" or ".", and it will use the mtime of the file. You can use that with the old archive to set the time after whose mtime you want items to be archived, so something like:

tar --newer-mtime=/home/s/scotts/oldfile.tar.gz -zcf /tmp/newfile.tar.gz /home/s/scotts

Note that this will remove the "/" prefix from pathnames when archiving, which is almost always what you want it to do.

-Scott
3 posts Page 1 of 1

Who is online

In total there are 30 users online :: 0 registered, 0 hidden and 30 guests (based on users active over the past 5 minutes)
Most users ever online was 999 on Mon May 10, 2021 1:02 am

Users browsing this forum: No registered users and 30 guests