Ubuntu backups using 7z (7zip)Last updated on March 13th, 2021
This week I want to look at the use of 7zip in creating an effective backup routine.
We all know we should backup regularly, but it’s a pain to do, and most of us have been burnt by the loss of data from time to time, caused by a lack of backing up.
Since moving to only use Ubuntu a couple of years ago now, I’ve used a series of applications and methods to backing up, but I’ve settled on 7zip as the most reliable way of giving me flexible backups. I’d best explain why!…
- No dependencies – Backup applications often use proprietary formats that means you need to be able to access that application to access your backups. Having backups that go back many years means this quickly becomes a compatibility challenge with backup apps.
- Secure offline nature – Simple offline backups do away with the risk of data being permanently online (like a cloud service), and therefore at risk of hacker attack. Although offline copies can be stolen, it is unlikely a house burglar would be after your backups.
- Easily encrypted – Just adding the “p” parameter ensures your backup is encrypted.
I’m sure some will say this is more complex than installing a backup application. For me however, it enables simple backup files I can copy to USB sticks, to keep a lot of history in a small box. The USB stick mention also makes it easy to place a copy of backups away from your house (e.g. a work locker, or family members house) to protect from fire/theft at home.
To backup my home directory, I use a command like the below:
sudo 7z a -r -p "/media/username/Partition Name/2017_04_09-home-dir.7z" /home/username
a = Add to archive
r = Recursive folder backup (backup everything within subfolders at the target too)
p = Add password (leave this blank and you’ll be prompted to provide one so it isn’t captured in shell logs)
It’s worth considering adding some “x” parameter arguments, to exclude any directories you don’t need to backup:
sudo 7z a -r -p '-x!Dropbox' '-x!Music' "/media/username/Partition Name/2017_04_09-home-dir.7z" /home/username