DEV Community

Cover image for Creating backups with split and zip in MacOS
Efe Ertugrul
Efe Ertugrul

Posted on

Creating backups with split and zip in MacOS

In this post i will show you how to split large files for easy upload and archive in MacOS.

Let's say there are large number of files in your desktop and size difference between these files are too big.
There are 2 Kilobyte files and there are more than 1 Gigabyte files.

Now if you don't have time and you just need to upload these to google drive or dropbox you might need to install their apps to your Mac.

If you don't want to install those apps to your Mac you can use a browser to upload these files but if anything goes wrong with a large file when uploading, you will lose time.

So rather uploading large files you can follow these steps:

1- Put everything in a .zip archive without compressing and encrypt it with a password.
2- Split that one big .zip file to many smaller files.
3- Check their integrity.
4- Upload them to cloud.
5- When you need that .zip file, download splitted files, merge and unzip it with correct password.

Now let's go to our terminal.


Let's say you have a folder named backup_desktop.

Archive backup_desktop/ directory, without compressing and encrypting with a password:

zip -0er backup-desktop.zip backup_desktop/
Enter fullscreen mode Exit fullscreen mode

This command will ask for a password and create a password protected .zip file named backup-desktop.zip.

-0er means:
0: no compression
e: encrypt it with a password
r: means whole directory


Split backup-desktop.zip in backup_split directory with backup-desktop- prefix:

split -b 1m backup-desktop.zip backup_split/backup-desktop-
Enter fullscreen mode Exit fullscreen mode

This will split backup-desktop.zip file and create five files with 1 Megabyte size. (because my backup-desktop.zip is 5 Megabyte)

-b 1m: means split to 1 Megabyte parts.
backup-desktop.zip: means split this file
backup_split/backup-desktop-: means save splitted parts to backup_split directory and save them with "backup-desktop-" prefix

My zip archive is rather small so you might want to change "-b 1m". I usually use "-b 25m" for large files. That creates files with 25 Megabyte sizes each.

My backup_split directory lists like this:

  • backup-desktop-aa
  • backup-desktop-ab
  • backup-desktop-ac
  • backup-desktop-ad
  • backup-desktop-ae
  • backup-desktop-af

All files start with backup-desktop- prefix as we asked.


Now before you use those, you should also check those files' integrity

Use md5 to print checksum of backup-desktop.zip file:

md5 -q backup-desktop.zip
Enter fullscreen mode Exit fullscreen mode

-q: means print only checksum

You will see a text. That is the checksum of backup-desktop.zip file.

Now we have to do the same thing for splitted files.
cat command will put all the splitted files together and md5 will print their put-together checksum:

cat backup_split/backup-desktop-* | md5 -q
Enter fullscreen mode Exit fullscreen mode

cat backup_split/backup-desktop-*: means merge files in backup_split with "backup-desktop-" prefix.
| md5 -q: means send that merged files to md5 -q and md5 -q will print another text which is splitted files' checksum.

Now if those two printed strings are identical that means files are healthy and those splitted files can be merge into backup-desktop.zip.

If two printed strings are not identical that means splitted files cannot merge into backup-desktop.zip.
something is wrong and you should not use those files.


Now you can upload your splitted files to your cloud server.


When you need that backup, download all splitted files into a directory and merge splitted files with this command:

cat backup-desktop-* > backup-desktop.zip
Enter fullscreen mode Exit fullscreen mode

cat backup-desktop-*: means merge every file in directory with backup-desktop- prefix.
> backup-desktop.zip: means save merged files as backup-desktop.zip

This command will create a file named backup-desktop.zip in that directory.

Now you can unzip it with this command:

unzip backup-desktop.zip
Enter fullscreen mode Exit fullscreen mode

It will ask your password for the zip file and if you enter right password, this command will create a directory named backup_desktop and will put all your archived files in it.

Also you can just double-click it. Archive Utility.app can do the same thing.

Top comments (0)