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