ho-aliyun-swas-disk-auto-snapshot
v1.1.1
Published
Aliyun SWAS disk automatic snapshot management tool
Downloads
6
Maintainers
Readme
ho-aliyun-swas-disk-auto-snapshot
English | 简体中文
Aliyun SWAS (Simple Application Server) disk automatic snapshot management tool. This tool helps you automatically create snapshots for your SWAS disks and clean up old snapshots based on retention policies.
Features
- List all snapshots for a disk
- Create snapshots manually or automatically
- Delete snapshots
- Clean old snapshots based on retention policy
- Automatic snapshot management (clean old + create new)
Installation
npm install -g ho-aliyun-swas-disk-auto-snapshotOr use locally:
npm install ho-aliyun-swas-disk-auto-snapshotConfiguration
1. Aliyun Credentials
Configure your Aliyun credentials using one of these methods:
Method 1: Environment Variables
export ALIBABA_CLOUD_ACCESS_KEY_ID=your-access-key-id
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=your-access-key-secretMethod 2: Aliyun CLI Profile
aliyun configureMethod 3: ECS RAM Role (if running on Aliyun ECS)
See Aliyun Credentials Documentation for more details.
2. Environment Configuration
Create a .env file in your project root (copy from .env.example):
cp .env.example .envEdit .env file:
# Required: Your SWAS disk ID
ALIYUN_DISK_ID=d-xxxxxxxxxxxxxx
# Optional: Region ID (default: cn-hongkong)
ALIYUN_REGION_ID=cn-hongkong
# Optional: API endpoint
ALIYUN_ENDPOINT=swas.cn-hongkong.aliyuncs.com
# Optional: Number of days to retain old snapshots (default: 7)
RETENTION_DAYS=7
# Optional: Prefix for auto-generated snapshot names (default: Auto)
# Note: Must start with uppercase letter
SNAPSHOT_PREFIX=Auto
# Optional: Maximum number of auto snapshots to keep
# 0 disables count-based pruning (default: 0)
# Example: keep at most 30 auto snapshots
MAX_SNAPSHOTS=0CLI Usage
Command aliases:
ho-aliyun-swas-snapshot(short)ho-aliyun-swas-disk-auto-snapshot(same as package name)
List Snapshots
ho-aliyun-swas-snapshot list
# With options
ho-aliyun-swas-snapshot list --region cn-hongkong --disk d-xxxxxCreate Snapshot
ho-aliyun-swas-snapshot create
# With custom name
ho-aliyun-swas-snapshot create --name "my-snapshot"
# With specific disk
ho-aliyun-swas-snapshot create --disk d-xxxxxDelete Snapshot
ho-aliyun-swas-snapshot delete <snapshot-id>Clean Old Snapshots
ho-aliyun-swas-snapshot clean
# With custom retention period
ho-aliyun-swas-snapshot clean --retention 14
# With count-based pruning (e.g., keep at most 30 auto snapshots)
ho-aliyun-swas-snapshot clean --max 30Auto Snapshot (Clean + Create)
ho-aliyun-swas-snapshot auto
# With custom options
ho-aliyun-swas-snapshot auto --retention 7 --prefix "Auto" --max 30Programmatic Usage
import { SnapshotManager } from 'ho-aliyun-swas-disk-auto-snapshot';
const manager = new SnapshotManager({
regionId: 'cn-hongkong',
diskId: 'd-xxxxxxxxxxxxx',
retentionDays: 7,
snapshotPrefix: 'Auto',
maxSnapshots: 30,
});
// List snapshots
const snapshots = await manager.listSnapshots();
// Create snapshot
const snapshotId = await manager.createSnapshot('my-snapshot');
// Delete snapshot
await manager.deleteSnapshot('s-xxxxxxxxxxxxx');
// Clean old snapshots
const deletedCount = await manager.cleanOldSnapshots();
// Auto snapshot (clean + create)
await manager.autoSnapshot();Quick Installation
Use the installation script for quick setup:
# Download and run installation script
curl -sSL https://raw.githubusercontent.com/willkan/ho-aliyun-swas-disk-auto-snaphot/main/install.sh | bash
# Or clone and run locally
git clone https://github.com/willkan/ho-aliyun-swas-disk-auto-snaphot.git
cd ho-aliyun-swas-disk-auto-snaphot
./install.shCron Job Setup
For detailed cron configuration, see CRON_SETUP.md.
Quick setup for daily snapshots:
# Edit crontab
crontab -e
# Add daily snapshot at 2:00 AM
0 2 * * * ~/swas-snapshot-config/run-snapshot.sh >> ~/swas-snapshot-config/logs/snapshot.log 2>&1Development
# Clone repository
git clone https://github.com/willkan/ho-aliyun-swas-disk-auto-snaphot.git
cd ho-aliyun-swas-disk-auto-snaphot
# Install dependencies
npm install
# Build
npm run build
# Run CLI locally
node dist/cli.js listLicense
MIT
