Safely cleaning up old files - Free up Storage Space

76 views
Skip to first unread message

Ryan Marsh

unread,
Jul 26, 2017, 12:36:45 PM7/26/17
to Canvas LMS Users
Hi folks,

Looking for some tips on freeing up some storage space for my Canvas Instance. I've got about 3 years of usage going and there's a lot of old SIS import .zip archives and several old Report .csv files that I'd like to get rid of (my /var/canvas directory is currently 11GB). I wasn't able to find anything in the Instructure documentation or here in the Group.

Any ideas / recommendations (other than add more storage, which I'm going to do anyway).

Thanks in advance,

Ryan

Christopher Bennell

unread,
Jul 31, 2017, 3:54:56 PM7/31/17
to Canvas LMS Users
This is the script I used to delete content exports (course exports etc). It would be a starting point for other types of files, like SIS import files. 

Christopher Bennell

unread,
Jul 31, 2017, 3:56:48 PM7/31/17
to Canvas LMS Users
I also started work on this for other types of attachments but it's unfinished and untested! I got some feedback from Instructure on it, so that helps. 


On Wednesday, July 26, 2017 at 12:36:45 PM UTC-4, Ryan Marsh wrote:

Ryan Marsh

unread,
Aug 1, 2017, 10:54:37 AM8/1/17
to Canvas LMS Users
Thanks for the links to the scripts Chris! Sadly, most of our courses are not using attachments. Most of my concern is coming from SIS Import files and Administrator Reports. I'm really looking for guidelines on what's safe to remove (manually or via script). For example, running API against the reports gives you an index of every report and where to download it from. If I go manually delete a report from the server, would that break the API???

Ryan

Christopher Bennell

unread,
Aug 3, 2017, 9:35:54 AM8/3/17
to Canvas LMS Users
"Attachment" is the term that Canvas uses for any file that is generated or uploaded to the system. When you generate a report, an attachment is created. That is to say an instance of the attachment model is created. 

My sense is that just deleting a report file from disk won't break Canvas, it's just a bit... untidy. It doesn't need to actually touch the file to generate the download URL. It would throw an error if someone tried to download that report. Your best bet is to test and find out. 

I think it would be easier to track those files down using the AccountReport & Attachment models. As far as I can tell, AccountReports don't seem to have any other associations that need to be cleaned up. So you could load your AccountReports, possibly filtering on report type, creation date, subaccount etc, then delete the attachments, then delete the reports. If I wanted to delete all SIS Export Reports, I might do something like the following (untested). Use the delete_attachment method from my link, but remove the call to content_export_for:

reports = AccountReport.where(report_type: 'sis_export_csv')
reports.each do |report|
  delete_attachment(report.attachment)
  report.delete
end

SIS Import files are a bit more tricky, because many other models seem to reference the SIS Batch that created them. Deleting them would leave a dangling reference. You could test deleting just the associated files from disk; I doubt that Canvas ever tries to access those files after the import. 

Good luck!

Cody Cutrer

unread,
Aug 9, 2017, 1:05:34 PM8/9/17
to canvas-l...@googlegroups.com
If you delete the files the API will continue to function, but the links generated to download the files will be broken.

Cody Cutrer
Software Engineer
Instructure

--

---
You received this message because you are subscribed to the Google Groups "Canvas LMS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages