Automatic file backup script that copies important files from a source directory to a backup folder with timestamps. This script helps protect your important data by creating regular backups with configurable settings.
- Automated Backup: Copies files from source to backup directory
- Timestamp-based Naming: Each backup is stored with a unique timestamp
- Configurable File Types: Specify which file extensions to backup
- Folder Exclusion: Exclude specific folders from backup (e.g., temp, cache)
- Automatic Cleanup: Removes old backups based on configurable retention policy
- Logging: Detailed logging of all backup operations
- JSON Configuration: Easy-to-edit configuration file
python auto_file_backup.py <source_directory> <backup_directory>python auto_file_backup.py /home/user/Documents /home/user/Backupspython auto_file_backup.py /home/user/Documents /home/user/Backups --config my_config.jsonThe script uses a backup_config.json file with the following structure:
{
"file_extensions": [".txt", ".pdf", ".doc", ".docx", ".xlsx"],
"exclude_folders": ["temp", "cache"],
"max_backups": 7
}- file_extensions: List of file extensions to include in backup
- exclude_folders: Folders to skip during backup
- max_backups: Maximum number of backup folders to keep (older ones are deleted)
- Python 3.6 or higher
- Standard library only (no external dependencies)
# Edit crontab
crontab -e
# Add this line for daily backup at 2 AM
0 2 * * * /usr/bin/python3 /path/to/auto_file_backup.py /source /backup- Open Task Scheduler
- Create Basic Task
- Set trigger to Daily
- Set action to run Python script with arguments
This script addresses issue #753 - Auto File Backup
Contributed to 100LinesOfPythonCode repository