# Disk space and backup failure notifications

**URL:** <https://meta.discourse.org/t/disk-space-and-backup-failure-notifications/24162>\
**Category:** Bug\
**Tags:** notifications, backups\
**Created:** [19.Январь.2015 00:05:44 UTC](https://meta.discourse.org/t/disk-space-and-backup-failure-notifications/24162 "2015-01-19T00:05:44Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [15.Май.2017 01:35:33 UTC](https://meta.discourse.org/t/disk-space-and-backup-failure-notifications/24162/11 "2017-05-15T01:35:33Z")

</div>

I can confirm this still occurs…

And I believe I have a solution…

### Background

Basically logging is unable to complete because the disk is full.

It is possible to allow logging to complete by deleting the intermediate files (`*.tar`) immediately after the error before attempting to log / send notifications for the event rather than leaving it until after.

### Initial change (didn’t quite work)

Changing the following **should** delete the `*.tar` file before attempting to log / send notifications.

#### From

> <https://github.com/discourse/discourse/blob/a4deb0e47db9368936d5755a2088999ad48bacf1/lib/backup_restore/backuper.rb#L54-L63>

#### To

```ruby
ensure
  clean_up

  begin
    notify_user
    remove_old
  rescue => ex
    Rails.logger.error("#{ex}\n" + ex.backtrace.join("\n"))
  end

  @success ? log("[SUCCESS]") : log("[FAILED]")

```

### Further changes required

I tested the above on a production installation - it didn’t work…

… I tracked down the problem to the function `remove_tar_leftovers`:

> <https://github.com/discourse/discourse/blob/a4deb0e47db9368936d5755a2088999ad48bacf1/lib/backup_restore/backuper.rb#L276-L279>

Whilst `system('rm', '-f', "#{@archive_directory}/*.tar")` looks like it should delete the tar file it doesn’t actually delete the file in this case.

I also tested the following, **none** of which deleted the `*.tar` file:

```ruby
#1
system('rm', '--verbose', '-f', "#{@archive_directory}/*.tar")

#2
stdout, stderr, status = Open3.capture3('rm', '--verbose', '-f', "#{@archive_directory}/*.tar")
log stdout
log stderr
log status

#3
FileUtils.rm_rf("#{@archive_directory}/*.tar")

```

Finally using the following actually deleted the file as expected when coupled with moving `clean_up` call earlier:

```ruby
log %x[rm --verbose -f #{@archive_directory}/*.tar 2>&1].inspect

```

This actually allowed the notifications to be delivered.

Hope this helps nail down complete solution.

---

_[View the full topic](https://meta.discourse.org/t/disk-space-and-backup-failure-notifications/24162)._
