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?
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.