Updated README.md

This commit is contained in:
2026-07-24 22:11:18 +01:00
parent a7d21be6bd
commit 47f9fb9048
+135
View File
@@ -0,0 +1,135 @@
# Cloudflare DNS Export Script
A bash script that exports DNS records from all Cloudflare zones configured in environment files, organizing exports by timestamp and domain.
## Overview
This script automates the process of exporting DNS records from Cloudflare. It reads API credentials from one or more .env configuration files, retrieves all zones associated with each account, and exports DNS records in BIND format to timestamped files.
## Requirements
- **bash** (4.0+)
- **curl** for API requests
- **jq** for JSON parsing
- Valid Cloudflare API token(s)
## Installation
1. Clone or download the script to your desired location.
2. Create the required directory structure:
```
mkdir -p envs
```
3. Set execute permissions:
```
chmod +x script.sh
```
## Configuration
### Environment Files
Create one or more `.env` files in the `envs` directory. Each file should contain:
```
CLOUDFLARE_API_TOKEN=your_api_token_here
```
To generate an API token:
1. Log in to your Cloudflare dashboard
2. Navigate to Account Settings > API Tokens
3. Create a token with "Zone.Zone" and "Zone.DNS" read permissions
4. Copy the token into your .env file
Multiple .env files are supported. The script will process each one separately.
## Usage
Run the script:
```
./script.sh
```
The script will:
1. Scan the `envs` directory for all .env files
2. For each .env file, authenticate with Cloudflare
3. Retrieve all zones associated with the API token
4. Export DNS records for each zone
5. Save exported records to timestamped files in the `export` directory
## Output
DNS exports are saved in the following structure:
```
export/
YYYY-MM-DD_HH-MM-SS/
domain1.com_YYYYMMDD_HHMMSS.txt
domain2.com_YYYYMMDD_HHMMSS.txt
...
```
Each export directory is named with a timestamp indicating when the export batch was created. Individual export files include the domain name and timestamp.
## Error Handling
The script uses strict mode (`set -euo pipefail`) to ensure:
- Exit on first error
- Undefined variables trigger errors
- Pipeline failures are caught
**Common issues:**
- **No .env files found**: Ensure .env files exist in the `envs` directory
- **CLOUDFLARE_API_TOKEN not set**: Verify the environment file contains the required token
- **jq not installed**: Install jq with `apt-get install jq` (Ubuntu/Debian) or `brew install jq` (macOS)
- **API errors**: Check that your token is valid and has appropriate permissions
## Notes
- Each .env file is processed independently with isolated variable scope
- DNS records are exported in BIND format
- The script creates timestamped subdirectories to prevent overwriting previous exports
- If multiple API tokens are used, exports will be organized in a single timestamped directory
# Disclaimer
#### Use at Your Own Risk
This script is provided "as is" without warranty of any kind, express or implied. The author assumes no responsibility for any damage, data loss, or other consequences resulting from the use of this script.
#### API Usage
Users are responsible for:
- Managing and protecting their Cloudflare API tokens
- Monitoring API usage and rate limits
- Complying with Cloudflare's Terms of Service
- Understanding the implications of exporting DNS data
Never commit .env files containing API tokens to version control systems or share them with unauthorized parties.
#### Data Security
Exported DNS records may contain sensitive configuration information. Store export files in secure locations with appropriate access controls. Be aware that DNS records can reveal information about your infrastructure.
#### Limitations
- This script relies on external APIs and network connectivity
- Cloudflare API rate limits may apply
- Large numbers of zones or DNS records may result in extended execution time
- The script requires specific dependencies (bash, curl, jq) to function correctly
#### Compatibility
This script is designed for Unix-like systems (Linux, macOS). Windows users may require additional tools or modifications to run this script successfully.
#### Support
This script is provided without dedicated support. Users are encouraged to review the code and test it in non-production environments before deploying to production systems.
#### Changes and Updates
The author reserves the right to modify or discontinue this script at any time. Users are responsible for maintaining their own backups and versions if desired.