Ubuntu backups using 7z (7zip)


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.

The command

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


I'm passionate about technology, and particularly helping people make the most of it. I've spent the last 30 years helping others make the most of technology. My career started in IBM, but I choose to move into smaller business environments, to use a breadth of skills, and help businesses step change their IT services. My skills range from user based technology, through business systems (applications) to infrastructure. I also have a long background in IT security. I focus on what I consider to be "productive technology", i.e. adding genuine value to peoples lives. I'm not a big gamer, and don't hold much interest in what I consider to be disposable consumer technologies. During the day, you'll find me consulting with businesses or heading up an IT department. At the weekend, you'll find me sat at my Linux PC, writing PHP or Python code, or trying to help others on Twitter, this blog, or my YouTube channel: Artexic.