0

On my server there is an application directory that I need to make a full copy of it but the copy takes up a lot of space, I need to compress it and then remove it. I already use the command

tar -czf bkp-mydir-$date.tar.gz mydir/

But I need it to be removed after the compression is done. In that case I could create a .sh file with the commands below:

 tar -czf bkp-mydir-$date.tar.gz mydir/
 rm -Rf mydir

I wanted to do this in Bacula.

Romeo Ninov
  • 5,263
  • 4
  • 20
  • 26
  • You don't need tar with bacula, it is a "tar" by itself, so to speak. And, bacula is a *backup* tool, not *data rearrange* tool. It is designed to copy data into its storage and leave it in place. If you want to do what you described, bacula is totally inappropriate tool. The power of solution like bacula stems from its scheduling, deduplication, filtering and other management; for the task as you described it, your "tar+rm" script (or some other way to archive files, like 7zip and so on) is probably the most appropriate way. – Nikita Kipriyanov Mar 22 '23 at 15:56
  • I understand how Bacula works (but thanks for the tip), but the idea is to compress the source directory and copy only the compressed file... – José Ferreira Neto Mar 23 '23 at 19:09
  • Bacula/BareOS can store data compressed (enable compression in the corresponding FileSet resource of the director configuration). That compression happens on the client, so it is transferred to the storage already compressed, saving network bandwidth. // It won't remove files from the source though. You can schedule tasks with Client Run Before Job and Client Run After Job, which can create tar file, backup it and remove everything afterwards, but that's silly. Seriously, this is not how Bacula or BareOS is supposed to be used. This is intended to extract databases into flat files to backup. – Nikita Kipriyanov Mar 24 '23 at 03:46

1 Answers1

0

Testing in my machine, the && worked very well in this case

tar -czf bkp-mydir-${date}.tar.gz mydir/ && rm -rf mydir/

You'll also need to use variable interpolation with the $date var. Check here: https://stackoverflow.com/questions/17622106/variable-interpolation-in-the-shell

Arrow Root
  • 102
  • 11