A command-line tool to batch restore files from Synology Drive's recycle bin based on deletion time. Perfect for recovering files after accidental bulk deletions.
- 🕐 Time-based filtering: Restore only files deleted after a specific timestamp
- 📦 Batch processing: Handles thousands of files efficiently (100 files per batch)
- 🔄 Async task monitoring: Track restoration progress in real-time
- 🔒 Secure authentication: Uses Synology's official API with cookie-based auth
- 📊 Progress tracking: Clear visual feedback during operation
- Python 3.6+
curlcommand-line tool- Synology NAS with Drive installed
- Admin or user account with Drive access
git clone https://github.com/yourusername/synology-drive-restore.git
cd synology-drive-restore
chmod +x restore.py monitor.pyCreate a config.json file:
{
"base_url": "https://your-nas-ip:5001",
"username": "your-username",
"password": "your-password",
"cutoff_timestamp": 1738224000
}To calculate timestamp:
python3 -c "from datetime import datetime; print(int(datetime(2026, 1, 30, 15, 0, 0).timestamp()))"./restore.pyThis will:
- Login to your Synology NAS
- Scan recycle bin for files deleted after the cutoff time
- Submit batch restore tasks
- Display progress
./monitor.pyMonitors all submitted tasks and shows real-time progress.
| Field | Description | Example |
|---|---|---|
base_url |
Your NAS URL (with port) | https://192.168.1.100:5001 |
username |
Synology account username | admin |
password |
Account password | your-password |
cutoff_timestamp |
Unix timestamp (files deleted after this time will be restored) | 1738224000 |
batch_size |
Files per batch (optional, default: 100) | 100 |
- Never commit
config.jsonwith real credentials to version control - Use a dedicated account with minimal permissions if possible
- Consider using environment variables for sensitive data
- The tool uses HTTPS but disables SSL verification (use at your own risk)
- Authentication: Logs in via Synology's Web API
- Scanning: Fetches recycle bin items in batches (1000 per request)
- Filtering: Keeps only files deleted after the specified timestamp
- Restoration: Submits async restore tasks (100 files per task)
- Monitoring: Polls task status until completion
SYNO.API.Auth- AuthenticationSYNO.SynologyDrive.Trash- List recycle bin itemsSYNO.SynologyDrive.Revisions- Restore filesSYNO.SynologyDrive.Tasks- Monitor task status
Login fails:
- Check URL, username, and password
- Ensure account has Drive access
- Verify NAS is accessible
No files found:
- Verify timestamp is correct (use Unix epoch time)
- Check if files are actually in recycle bin
- Ensure you're using the correct Drive path (
/mydrive)
Tasks stuck:
- Large files take longer to restore
- Check NAS system resources
- Monitor via DSM web interface
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request
MIT License - see LICENSE file for details.
This tool is provided as-is. Always backup important data before performing bulk operations. The author is not responsible for any data loss.
一个命令行工具,用于根据删除时间批量恢复 Synology Drive 回收站中的文件。非常适合在意外批量删除后恢复文件。
- 🕐 基于时间过滤:仅恢复指定时间戳之后删除的文件
- 📦 批量处理:高效处理数千个文件(每批100个)
- 🔄 异步任务监控:实时跟踪恢复进度
- 🔒 安全认证:使用群晖官方 API 和基于 Cookie 的认证
- 📊 进度跟踪:操作过程中提供清晰的视觉反馈
- Python 3.6+
curl命令行工具- 安装了 Drive 的群晖 NAS
- 具有 Drive 访问权限的管理员或用户账户
git clone https://github.com/yourusername/synology-drive-restore.git
cd synology-drive-restore
chmod +x restore.py monitor.py创建 config.json 文件:
{
"base_url": "https://你的NAS地址:5001",
"username": "你的用户名",
"password": "你的密码",
"cutoff_timestamp": 1738224000
}计算时间戳:
python3 -c "from datetime import datetime; print(int(datetime(2026, 1, 30, 15, 0, 0).timestamp()))"./restore.py这将:
- 登录到你的群晖 NAS
- 扫描回收站中截止时间后删除的文件
- 提交批量恢复任务
- 显示进度
./monitor.py监控所有已提交的任务并显示实时进度。
| 字段 | 说明 | 示例 |
|---|---|---|
base_url |
NAS 地址(含端口) | https://192.168.1.100:5001 |
username |
群晖账户用户名 | admin |
password |
账户密码 | your-password |
cutoff_timestamp |
Unix 时间戳(此时间后删除的文件将被恢复) | 1738224000 |
batch_size |
每批文件数(可选,默认:100) | 100 |
- 切勿将包含真实凭据的
config.json提交到版本控制 - 如果可能,使用具有最小权限的专用账户
- 考虑使用环境变量存储敏感数据
- 该工具使用 HTTPS 但禁用了 SSL 验证(使用风险自负)
- 认证:通过群晖 Web API 登录
- 扫描:批量获取回收站项目(每次请求1000个)
- 过滤:仅保留指定时间戳之后删除的文件
- 恢复:提交异步恢复任务(每个任务100个文件)
- 监控:轮询任务状态直到完成
SYNO.API.Auth- 认证SYNO.SynologyDrive.Trash- 列出回收站项目SYNO.SynologyDrive.Revisions- 恢复文件SYNO.SynologyDrive.Tasks- 监控任务状态
登录失败:
- 检查 URL、用户名和密码
- 确保账户具有 Drive 访问权限
- 验证 NAS 可访问
未找到文件:
- 验证时间戳是否正确(使用 Unix 纪元时间)
- 检查文件是否确实在回收站中
- 确保使用正确的 Drive 路径(
/mydrive)
任务卡住:
- 大文件恢复需要更长时间
- 检查 NAS 系统资源
- 通过 DSM Web 界面监控
欢迎贡献!请:
- Fork 仓库
- 创建功能分支
- 提交 Pull Request
MIT 许可证 - 详见 LICENSE 文件。
此工具按原样提供。在执行批量操作之前,请始终备份重要数据。作者不对任何数据丢失负责。