3

Is it safe to create a tarball of a directory while the files in the directory are being used (read+write)?

I want to create a backup of a 20GB directory without having to shut down my application server.

I don't mind if the files are changed while the tar is being created, as long as every file is present in the archive, I'm fine with it.

Elite_Dragon1337
  • 216
  • 1
  • 2
  • 10

2 Answers2

6

It depends. When you're making tarbal (or rsync copy) of changing data, files will be copied in state when copy of that one file started. And that is a trap. If you will have ie. 100 files in directory, all those files will be changing during backup and backup of one file will takes 1s, last copied file will be for 99s newer than first one. This can lead to useless backup if you need all data presenting same time window (ie. you cannot backup database this way).

Ondra Sniper Flidr
  • 2,653
  • 12
  • 18
1

While what Ondra Sniper Flidr writes is true, tar has the habit of refusing to work if the directory changes after it starts archiving. So no, it does not work right even in the scenarios where it should be safe.

joshudson
  • 421
  • 4
  • 11