0

I have a folder with some files. I need to backup them daily.

I am using Debian and zsh and I use zip for the tool to backup them.

I am updating the folder from time to time, adding new files, removing old files and updating old files.

I noticed that zip can automatically update a zip file. For instance:

When I run zip -r backup.zip my-folder/ at first, it will add all files.

But when I run the same command zip -r backup.zip my-folder/ again, it will update all the files.

Is that reliable? Or do I need to rm the zip file every time before I pack my folder?

  • 3
    Another question to consider is whether zip is a good tool for doing backups at all. I would rather consider rsnapshot, borgbackup or similar. – Kusalananda Aug 5 '18 at 7:40
1

According to man zip

zip  will  replace identically named entries in the zip archive

So whenever zip says updating: my-folder/<file> (in=0) (out=0) (stored 0%) its actually replacing the existing file in the archive, which is like a Full backup but not an Incremental or Defferential Backup. Checkout the example below:

# du -b dir/*
1073741824  dir/file.txt
2   dir/x
0   dir/xx
0   dir/xy
0   dir/y
0   dir/z


# time zip -rv dir.zip dir
  adding: dir/  (in=0) (out=0) (stored 0%)
  adding: dir/xy    (in=0) (out=0) (stored 0%)
  adding: dir/x (in=2) (out=2) (stored 0%)
  adding: dir/file.txt ......................................................................................................   (in=1073741824) (out=1042051) (deflated 100%)
  adding: dir/xx    (in=0) (out=0) (stored 0%)
  adding: dir/y (in=0) (out=0) (stored 0%)
  adding: dir/z (in=0) (out=0) (stored 0%)
total bytes=1073741826, compressed=1042053 -> 100% savings

real    0m10.990s
user    0m10.827s
sys 0m0.160s

# dd if=/dev/zero of=dir/file.txt count=1040 bs=1048576 
1040+0 records in
1040+0 records out
1090519040 bytes (1.1 GB) copied, 8.95635 s, 122 MB/s

# du -b dir/file.txt 
1090519040  dir/file.txt

Now the file dir/file.txt has been updated with some extra bytes. Now lets run zip again:

# time zip -rv dir.zip dir
updating: dir/  (in=0) (out=0) (stored 0%)
updating: dir/xy    (in=0) (out=0) (stored 0%)
updating: dir/x (in=2) (out=2) (stored 0%)
updating: dir/file.txt ........................................................................................................ (in=1090519040) (out=1058320) (deflated 100%)
updating: dir/xx    (in=0) (out=0) (stored 0%)
updating: dir/y (in=0) (out=0) (stored 0%)
updating: dir/z (in=0) (out=0) (stored 0%)
total bytes=1090519042, compressed=1058322 -> 100% savings

real    0m11.246s
user    0m11.021s
sys 0m0.223s

It just replaced the dir/file.txt with recently modified file with the same name. This is the same case even if the file doesn't have new content. There are different types of backups like Full, Incremental, Differential available. Typically Incremental and Differential will come into the picture if the Backup mechanism is designed and put in place for the Data.

In that case as @kusalananda mentioned it would be good if you looked at more versatile tools available to take backups.

For instance rsync could be of help.

Also rm need not be run on the existing archived file every time you run the zip command.

If you want to stick with zip, go through zip's add, update, freshen. For example, Update case:

# time zip -ruv dir.zip dir
zip diagnostic: dir/ up to date
zip diagnostic: dir/xy up to date
zip diagnostic: dir/x up to date
zip diagnostic: dir/xx up to date
zip diagnostic: dir/y up to date
zip diagnostic: dir/z up to date
updating: dir/file.txt ..........................................................................................................   (in=1111490560) (out=1078679) (deflated 100%)
total bytes=1111490562, compressed=1078681 -> 100% savings

real    0m11.351s
user    0m11.178s
sys 0m0.171s

If zip is run again:

# time zip -ruv dir.zip dir
zip diagnostic: dir/ up to date
zip diagnostic: dir/xy up to date
zip diagnostic: dir/x up to date
zip diagnostic: dir/file.txt up to date
zip diagnostic: dir/xx up to date
zip diagnostic: dir/y up to date
zip diagnostic: dir/z up to date

real    0m0.003s
user    0m0.002s
sys 0m0.001s

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.