Skip to content

Automatic Local Directory Backup with File Rotation #17

@ajayparihar

Description

@ajayparihar

Add a user-configurable automatic backup feature that allows users to specify a local directory path in their profile settings. The application should automatically save backup files to the specified location whenever changes are made to snippets, and maintain only the 10 most recent backup files by automatically deleting older ones.

Current Behavior:
Users must manually export JSON/CSV files when they want to create backups.
Backups are only created on-demand through the export menu.
No automatic or scheduled backup functionality exists.
Backup files are downloaded to the default Downloads folder with generic names.
Old backup files accumulate without cleanup.

Expected Behavior:
Add a "Backup Location" field in the Profile settings modal.
Users can browse and select a local directory for automatic backups.
Application automatically saves a timestamped backup file to the specified directory whenever data changes occur (add/edit/delete snippets, profile updates).
Backup files should have descriptive names with timestamps (e.g., "compy-backup-2025-08-25-17-30.json").
Maintain only the 10 most recent backup files in the specified directory.
When the 11th backup file is created, automatically delete the oldest backup file.
Show backup status indicator in the UI (last backup time, number of backup files).

User Stories:
As a user, I want to set a specific folder where my snippets are automatically backed up so I don't lose important data.
As a user, I want old backup files automatically cleaned up so they don't clutter my backup directory.
As a power user, I want my snippets automatically saved to my cloud sync folder with automatic file rotation to manage storage space.
As a frequent user, I want to see when the last backup occurred and how many backup files are maintained.

Acceptance Criteria:

Profile settings include a "Backup Location" field with folder browser

Users can select and change the backup directory path

Automatic backup triggers on any data modification

Backup files use descriptive timestamp-based naming

Only keep the 10 most recent backup files

Automatically delete the oldest file when creating the 11th backup

Backup location preference persists across sessions

Show backup status (last backup time, file count) in UI

Handle backup failures gracefully with user notifications

Support cross-platform directory paths (Windows, Mac, Linux)

File rotation works reliably without leaving orphaned files

Technical Considerations:
Requires File System Access API for modern browsers or fallback options.
Need to handle browser security restrictions for local file access.
Implement file enumeration to identify and sort existing backup files by creation date.
Add logic to delete oldest files before creating new ones.
Store backup location preference in localStorage with the profile data.
Implement debounced backup to avoid excessive file operations during rapid changes.
Add error handling for file deletion failures or permission issues.
Track backup file names to ensure proper cleanup of application-generated files only.

Browser Limitations:
File System Access API only works in Chromium-based browsers (Chrome, Edge).
Requires user permission for each directory access.
May need fallback to manual downloads for unsupported browsers.
Cannot write to arbitrary locations without explicit user consent.
File deletion requires additional permissions beyond write access.

Priority: Low-Medium — Provides valuable data protection for power users with automatic cleanup, but limited by browser security constraints and cross-browser compatibility issues.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions