Sub topic 15
Protecting and retaining exported files
This chapter assumes you can already produce exports with the Data Export Service, Data Loader, or the Salesforce CLI, and that you can work in a terminal. It covers what to do with the files afterward.
Why exported files are a risk
An export is a full copy of your records outside Salesforce's controls. Field-level security, sharing rules, and login audit trails no longer apply to it. A CSV of Contacts can leak personal data as easily as a stolen laptop can. Treat every export as production data.
Control who can reach the files
Apply least privilege to both the people and the tools that touch backups.
- Store files in a location limited to a small named group, such as a private bucket or a restricted network share.
- Use a dedicated integration user for scheduled exports, not an administrator's personal login.
- Give that user only the access it needs. A user who can see every field exports every field, so check what the profile and permission sets expose.
- Keep access tokens and passwords out of scripts. Read them from environment variables or a secrets manager.
- Never email export files or leave them in a shared download folder.
The Data Export Service produces download links that expire after a short period. Download the files promptly, move them to your storage location, and do not forward the links.
Encrypt at rest and in transit
Move files only over HTTPS or SSH. For storage, turn on encryption at rest in your storage service. For extra protection, encrypt each archive before it leaves the machine that created it.
#!/usr/bin/env bash
set -euo pipefail
SRC="backup/$(date +%Y%m%d)"
tar -czf "$SRC.tar.gz" "$SRC"
gpg --symmetric --cipher-algo AES256 \
--batch --pinentry-mode loopback \
--passphrase-file /etc/backup/passphrase \
"$SRC.tar.gz"
rm -r "$SRC" "$SRC.tar.gz"The script bundles the dated folder, encrypts it with AES-256, and removes the plaintext copies. Keep the passphrase file readable only by the backup account, and store a copy of the passphrase apart from the backups. An encrypted archive without its key cannot be restored.
Set a retention policy
Keeping every export forever raises both cost and exposure. Deleting too early leaves you without a usable restore point. Decide the schedule deliberately and write it down.
| Copy | Example retention | Purpose |
|---|---|---|
| Daily | 14 days | Recover from recent mistakes |
| Weekly | 8 weeks | Recover from problems noticed late |
| Monthly | 12 months | Audit and long-term recovery |
Check your legal obligations too. Privacy rules such as GDPR may require you to delete a person's data on request, and that duty extends to your backups. Shorter retention makes this easier to meet.
Common mistakes
- Leaving plaintext CSVs on the machine that ran the export.
- Storing the encryption key next to the backups it protects.
- Using one shared administrator login for every scheduled job.
- Never reviewing who can read the backup location.
Exercise
Your nightly job exports Contacts to a CSV on a build server and leaves the file there. Name three changes that would improve its protection.
Show answer
Encrypt the archive and delete the plaintext copy after the job runs. Upload it to restricted, encrypted storage with access limited to a named group. Run the job as a dedicated integration user with minimal permissions, and apply a retention rule so old copies are deleted automatically. Keeping the encryption key separate from the backups also counts.