I would like to backup my entire home directory on Linux. Suppose this directory is the only one I have write permissions to.
How would I tar-gzip this directory and put result inside itself?
tar zcf home-backup.tar.gz --exclude ./home-backup.tar.gz .
home-backup.tar.gz not only the one you're creating here. With GNU tar (not with bsdtar), you can use --exclude ./home-backup.tar.gz to avoid it.
./ to exlcude just the one file)
The already suggested
tar zcf home-backup.tar.gz --exclude home-backup.tar.gz .
would work, but I don't really like that kind of tars which contain lots of files instead of only one directory. If you want to do the same but as one directory:
cd /home
tar -czf yourhome/yourhome.tgz --exclude yourhome.tgz yourhome/
In both case you will get an error message:
tar: yourhome: file changed as we read it
which can be a problem if you want to backup from a script and checking the exit code, and anyway if you ignore this it could hide another problem. You can eliminate this creating an empty tgz before you start the backup:
touch yourhome.tgz
If you use a working modern tar implementation, this will work the way you like out of the box:
star -cz . > archive.tar.gz
will print the warning:
star: 'archive.tar.gz' is the archive. Not dumped.
tar zcf archive.tar.gz . works with my version of GNU tar, but causes the directory modified warning mentioned by @redseven.
/tmp, too.