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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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: