diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index a06e35226bbbeb108ea27383b4bfabefc81e1bd9..9202b4839cee233a89fdb83e07bc9d16b96297b6 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -476,8 +476,10 @@ namespace :mastodon do
       time_ago = ENV.fetch('NUM_DAYS') { 7 }.to_i.days.ago
 
       MediaAttachment.where.not(remote_url: '').where.not(file_file_name: nil).where('created_at < ?', time_ago).find_each do |media|
-        media.file.destroy
-        media.save
+        if media.file.exists?
+          media.file.destroy
+          media.save
+        end
       end
     end