Linode Backup Failure: Too Many Files
After a recent Backup Failure ticket, I was told that my Linode has too many files on it. It looks like it’s mostly session and tmp files. What’s a good way to deal with these files moving forward to both get my backups running again and so I don’t have to worry about this again?
2 Replies
Because our Backup service is file-based, the overall number of files on the Linode will affect both the time needed for a backup to run, but also the time needed for any restore jobs. This is one of the limtations for our service. There isn’t a magic number to avoid, as this limitation can be triggered by large number of small files, or a specific directory with a large number of files.
If you wish to get your backups …back up and running, you have two options:
- Get rid of those files
- Keep those files
Both of these options can be handled automatically by your Linode.
Removing Files
For removing files, a simple cron job with the correct scheduling, can remove any unnecessary files. Below I’ll provide some tips on setting up a cron to remove files from a directory, though if you’d like a deeper dive into cron, check out our guide: Schedule Tasks with Cron
Cron is a scheduling daemon that will watch the clock and run a command that you tell it to when you tell it to run. These are managed through crontab, or cron tables. Using crontab, you can set a schedule and a script or command for it to run at that time.
First, you’ll want to identify which directories need to be addressed. To find directories with a lot of files:
sudo find / -type f | perl -aF/ -lne 'for (my $i=0; $i < @F-1; ++$i) { print join("/",@F[0...$i]); }' | sort | uniq -c | sort -n | tail -30
Once you know the absolute path that you’re looking to keep the file count down in, you’re ready to set up the cron job. Start by bringing up the crontab editor. The text editor it uses (nano, vi, etc), will be based on your Linode’s settings:
crontab -e
Next, at the end of the file, under all the commented out lines, you’ll add the command for removing the files. A sample entry could look like this:
0 0 * * 0 rm -rf /path/to/directory/you/wish/to/delete/*
This will run the rm
command for all files in the directory every Sunday.
Important note: without appending the asterisk at the end, it will attempt to remove the directory, which could disrupt services that are looking to write to a specific directory.
Possible options for frequency:
Monthly:
0 0 1 * * rm -rf /directory/path/to/delete/*
Weekly:
0 0 * * 0 rm -rf /directory/path/to/delete/*
If you want to schedule this cron job for a different time, cron scheduling can be a little confusing. I used this site to help me with getting the right syntax:
Keep the files
If the files are important and can’t be removed, you have the option of archiving them into a compressed file to reduce overall file count. Using the [logrotate: https://www.linode.com/docs/uptime/logs/use-logrotate-to-manage-log-files/] can enable you to automatically compress the files in a directory to keep the files size getting to a point where it hits the limitation.
In the logrotate.conf
file, you’ll want to uncomment out the line that reads compress
. By default, it’s commented out, so it won’t compress the files.
Then, you’ll want to add the directories, which will look something like this:
/path/to/the/directory {
missingok
monthly
create 0664 root utmp
rotate 1
}
I took that example from the default logrotate.conf file, but changed the path for my example. The doc on logrotate that I linked above goes into greater detail on what each of those parameters are, how they behave, and other ones your might want to include, such as emailing yourself the logs to store off the Linode.
If you’re just looking to do a one-time archive, we have great documentation on how to do that as well:
Our Docs team is always coming up with helpful new resources that it's sometimes hard to keep up with all the latest goodies they create. Somehow, the following guide eluded me since it's 2021 publishing:
How to Check and Clean a Linux System's Disk Space | Linode Docs
That guide covers some basics around reviewing our system's storage usage and cleaning up accumulated files that have stuck around beyond their intended usefulness. The steps mentioned will surely help clear up the number of files on any Linode that has been around for a while. I recommend reviewing it if you've ended up here as a result of getting a "too many files" failure on your Linode's backups.