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.

3
  • 1
    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. Mar 22, 2023 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... Mar 23, 2023 at 19:09
  • 1
    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. Mar 24, 2023 at 3:46

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .