Data and Log Retention: What, How Much, and How Long to Keep

Define data retention periods by type: access logs, backups, customer data, and billing history each require their own retention period and storage location.

7 min Updated 18 Nov 2026

You're looking for a number. Someone asked you "how long do we keep the logs?" and you don't know whether to say 30 days or 90 days or "until the disk fills up." Or a service has been canceled and the customer asks when their data will be deleted, and you're not sure it gets deleted at all. This article gives you those numbers and those definitions—not a from-scratch configuration tutorial.

Let me say one thing up front: "data retention period" is not a single number. There are at least six categories of data on your server, each requiring a different retention period, and if you lump them all under one policy, either your storage costs multiply or you get caught in an audit.

Six data categories and the period they actually need

Review this table with your team. The last column is the most important: the place where data must actually be deleted, not just hidden from view.

CategorySuggested periodStorage locationDeletion note
Web access log14 to 30 daysLocal disk or centralized log serviceAutomatic rotation with logrotate
Error log and application log30 to 90 daysLocal disk + cold archiveMandatory gzip compression
Authentication and SSH logs90 days to one yearRead-only, separate from the main serverNo deletion until the period ends
Database backup7 days daily + 4 weeks weekly + 12 months monthlyOff the main serverDelete old versions on schedule
Customer data (profile, orders, tickets)Until end of contract + legal period thereafterMain databaseActual deletion after the period ends
Billing and payment historyUsually several years, per accounting requirementsFinancial systemUsually exempt from deletion

Take the third row seriously. The SSH log is the only place where, after a breach, you can reconstruct what happened. If you delete it after 14 days and the breach occurred three weeks ago, you have no evidence. This is the only category where I lean toward a longer period, not a shorter one.

Why I don't keep access logs longer than 30 days

A web server with moderate traffic generates several hundred megabytes of logs per day. Keeping it for three hundred days means tens of gigabytes that nobody reads, yet every search on it is slow and every backup is heavier. Worse: if those logs are on the same disk as the database, filling the disk causes a No space left on device error in MySQL and the site goes down. The cause of the failure isn't the log itself; it's the absence of a rotation policy.

The configuration I put on almost every server is this:

/var/log/nginx/*.log {
    daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
    sharedscripts
    postrotate
        systemctl reload nginx > /dev/null 2>&1 || true
    endscript
}

rotate 30 with daily means thirty compressed copies, about one month. Don't remove delaycompress; without it, the freshly rotated file also gets compressed and tools still writing to it throw errors. With logrotate -d /etc/logrotate.d/nginx you can see a dry-run output before applying it.

This is where people go wrong

The common mistake is conflating rotate 30 with "30 days of retention," when if it's weekly it's thirty weeks. I've seen a team think logs were being deleted after a month, then discover six months later that the disk was full. The symptom is obvious too: df -h on the /var partition shows a high percentage while du -sh /var/log gives a small number, because deleted files are still being held open by a process. With lsof +L1 you can see which process is holding the deleted file; the fix is restarting that service, not manual deletion.

What remains after service cancellation, and for how long

This is the part with the most misunderstanding. When a hosting service is canceled, three separate things happen and you need a specific number for each.

  1. Access: cut off immediately. The site and panel are shut down.
  2. Temporary retention: data stays on disk for a while so that if the customer returns, recovery is possible. Write this period into the contract; the common number is somewhere between a few days and a few weeks.
  3. Final deletion: after the period ends, the disk is wiped and overwritten. Automatic backups must also be deleted at this stage, otherwise the data lives on in backups.

The problem that arises in practice is that stage three gets written into the documentation but gets lost in the operational process. You see the result in an audit: the customer deleted their data, but a backup from six months ago is still sitting on an archive server. If you want to be sure, compare the list of backups against the list of active customers; any backup whose owner is no longer a customer should be in the deletion queue.

There's one exception: financial and billing data are usually outside this cycle and remain for years per accounting requirements. Tell the customer this in advance so they don't think "complete deletion" means everything.

Data that shouldn't be stored at all

Before setting a retention period, ask whether this data should exist at all. Access logs typically record the full IP address, request path, and User-Agent. If a login token or password is in the query string in that same log, you've stored passwords in a file that every team member can read. I once saw ?token=... in an nginx log and nobody had noticed.

Two quick actions: first, strip sensitive parameters from the log or don't log sensitive paths at all. Second, lock down the permission level of log files. The guide on setting secure file permissions in Linux covers exactly this; the short version is that logs shouldn't be 644 owned by the web user.

If you have a WordPress site, plugin logs and contact form logs get added to this list too. A contact form is full of names, emails, and message text; this is customer data, not technical logs, and you should put it in the "customer data" category. For the overall framework of legal and cookie pages, the site privacy guide is a good starting point.

Where to write the data retention policy

A short text file is enough, as long as it has three things: category name, period, and the person responsible for deletion. If the responsible person isn't specified, deletion never happens. Sample line:

access_log | 30d | logrotate | owner: ops
db_backup  | 7d daily / 12m monthly | backup-job | owner: dba
customer   | contract + 90d | manual review | owner: support-lead

Keep this where the team actually looks, not in a wiki that was last opened a year ago. And every time you add a new service, add a line to it. A policy that doesn't cover a new service isn't a policy.

The cost you have to accept

Shorter retention means lower storage cost and a lower risk surface, but it means that when a customer says three weeks later "my order is missing," you can't open the log and prove what happened. In most cases I choose 30 days, and for services with financial transactions I go to 90 days. If your business is in an area with lots of complaints and refunds, raise the number and accept the disk cost. The right decision depends on which pain is worse: a full disk, or the absence of evidence.

If your concern is the server's own security and not just data, look at blocking malicious IPs and closing extra access separately from this discussion; the guides on blocking malicious IPs and enabling two-factor authentication both work on the same principle: keep less, leave less open. For the network layer too, if a volumetric attack reaches the server, ServerNet security services is an option evaluated at this level.

Frequently asked questions

How often should server logs be deleted?

Keep web access logs for 14 to 30 days and error logs for 30 to 90 days. Don't keep authentication and SSH logs for less than 90 days, because that's the only evidence for reconstructing a breach. More important than the number is that deletion is automatic; if you delete manually, in practice it doesn't get deleted.

After service cancellation, how long does the data remain?

Usually a short temporary retention period to allow recovery, then final deletion. You should find the length of this period in the contract or service documentation, not guess it. Financial and billing data are usually exempt from this cycle and remain longer per accounting requirements.

Does deleting a file from the server mean the data is really gone?

No. As long as a process holds the file open, the space isn't freed and it's still visible with lsof +L1. At the disk level too, until it's overwritten, recovery is possible. For sensitive data, secure deletion or encryption at the source is required.

Is data retention subject to specific laws?

It depends on the business area and where your customers are. The minimum you should do in any case is document the retention period for each category, inform the customer, and actually carry out deletion. A policy that exists only on paper is worthless in an audit.

Next step: today, take the list of six categories above and write a number and a responsible person's name for each. If you can't give a number for more than two categories, it means you don't have a data retention policy and you just think you do.

Was this page helpful?