Plan and validate scheduled local-folder-to-OSS uploads with an aliyun-CLI-first workflow.
This skill covers the case where a local folder changes over time and must be uploaded to OSS on a recurring schedule.
Architecture: Local folder + aliyun CLI (integrated ossutil) + cron/Task Scheduler + OSS Bucket
Capability split:
[aliyun CLI] installation checks, profile verification, command discovery, OSS-side verification, and integrated aliyun ossutil upload/list commands.[OS-local] cron or Windows Task Scheduler configuration.[Manual/Console] RAM policy attachment and optional visual verification in the OSS Console.Pre-check: Aliyun CLI >= 3.3.3 required Run
aliyun versionto verify>= 3.3.3. If not installed or version too low, seereferences/cli-installation-guide.mdfor installation instructions. Then runaliyun configure set --auto-plugin-install true. At the start of the Core Workflow (before any CLI invocation): [MUST] Enable AI-Mode — AI-mode is required for Agent Skill execution. Run the following commands before any CLI invocation:bash
aliyun configure ai-mode enable aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload"[MUST] Disable AI-Mode at EVERY exit point — Before delivering the final response for ANY reason, always disable AI-mode first. This applies to ALL exit paths: workflow success, workflow failure, error/exception, user cancellation, session end, or any other scenario where no further CLI commands will be executed. AI-mode is only used for Agent Skill invocation scenarios and MUST NOT remain enabled after the skill stops running.
bash
aliyun configure ai-mode disable
[MUST] CLI User-Agent — Every
aliyunCLI command invocation must include:--user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload
Required local tools:
ToolRequiredPurposeVerifyaliyun CLIYesCredential gate, command discovery, and integrated ossutil upload/list surfacealiyun version and aliyun ossutil --help``cron or schtasksYesLocal recurring executioncrontab -l or schtasks /Query /TN "OSS Scheduled Sync"
Use references/cli-installation-guide.md only for CLI installation and plugin setup. For this skill, use the integrated aliyun ossutil command surface — do not require standalone ossutil installation or bare ossutil commands.
No extra cloud-specific environment variables are required beyond an already configured Alibaba Cloud profile.
Optional local variables used in examples:
VariableRequired/OptionalDescriptionDefault ValueALIBABA_CLOUD_PROFILEOptionalSelect a preconfigured Alibaba Cloud CLI profileCLI current profileALIYUN_BINOptionalAbsolute path to aliyun if it is not already in PATH``aliyun``OSS_SYNC_LOGOptionalLog file path for scheduled executionOS-specific local path
Parameter Extraction — Extract all user-customizable parameters directly from the user's request. When the user's message already specifies values (such as region, bucket name, paths, schedule, or MaxAge), use those values directly without asking for re-confirmation. Only ask the user for clarification when a required parameter is genuinely missing from their request and cannot be reasonably inferred from context.
Parameter NameRequired/OptionalDescriptionValidation PatternDefault ValueRegionIdRequiredOSS region such as cn-hangzhou`^[a-z]{2}-[a-z]+(-[0-9]+)$`BucketNameRequiredTarget OSS bucket name^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$NoneTargetOssPrefixRequiredBucket-relative target OSS prefix such as backup/photos/ (confirm without a leading /)^[A-Za-z0-9/_.-]*$ (no leading /)NoneLocalSourcePathRequiredLocal folder to uploadAbsolute path, no ~, $, backtick, or ;NoneScheduleRequiredCron expression or Windows schedule time/frequencyStandard 5-field cron or schtasks timeNoneMaxAgeRequiredaliyun ossutil --max-age window such as 7d or 24h``^[0-9]+[dhm]$NoneOperatingSystemRequiredlinux, macos, or windows`^(linuxmacosBucketAlreadyExistsRequiredWhether the target bucket already exists`^(yesno)$`AliyunBinaryPathOptionalAbsolute path to aliyun for scheduler useAbsolute path, no $, backtick, or ;``aliyun``LogPathOptionalLocal log path for the scheduled jobAbsolute path, no $, backtick, or ;OS-specific local path
Input Validation — All parameters must be validated before use. Treat all inputs (including values extracted from user messages) as untrusted. Before substituting any parameter into a shell command:
- Validate the value against the Validation Pattern column above. Reject values that do not match.
BucketNamemust contain only lowercase letters, digits, and hyphens ([a-z0-9-]), be 3–63 characters, and must not start or end with a hyphen.RegionIdmust match the Alibaba Cloud region format (e.g.,cn-hangzhou,us-west-1,ap-southeast-5).MaxAgemust be a positive integer followed byd(days),h(hours), orm(minutes).LocalSourcePath,AliyunBinaryPath, andLogPathmust be absolute paths and must not contain shell metacharacters ($,`,$(,;,|,&,>,<,\n).TargetOssPrefixmust contain only alphanumeric characters,/,_,., and-, and must not start with/.- If any parameter fails validation, stop and report the error to the user. Do not attempt to sanitize or escape invalid values — reject them outright.
Pre-check: Alibaba Cloud Credentials Required
Security Rules:
- NEVER read, echo, or print AK/SK values (e.g.,
echo $ALIBABA_CLOUD_ACCESS_KEY_IDis FORBIDDEN)- NEVER read or
catcredential files such as~/.aliyun/config.json,~/.ossutil/config, or any file that may contain secrets- NEVER ask the user to input AK/SK directly in the conversation or command line
- NEVER use
aliyun configure setwith literal credential values- ONLY use
aliyun configure listto check credential statusbash
aliyun configure listCheck the output for a valid profile (AK, STS, or OAuth identity).
If no valid profile exists, STOP here.
- Obtain credentials from Alibaba Cloud Console
- Configure credentials outside of this session (via
aliyun configurein terminal or environment variables in shell profile)- Return and re-run after
aliyun configure listshows a valid profile
Reuse the active CLI profile for all aliyun ossutil commands. Do not print or hardcode secrets. Do not replace this gate with ossutil config or any other secret-entry flow.
The default workflow needs least-privilege access for bucket discovery, bucket metadata verification, and object upload under the confirmed prefix.
ScopeRequired ActionsAccount-level verificationoss:ListBucketsTarget bucket verificationoss:GetBucketInfoIncremental upload to target prefixoss:PutObject, oss:GetObject, oss:ListObjectsOptional test cleanuposs:DeleteObject
Use references/ram-policies.md for the policy JSON and the prefix-scoped resource examples.
Do not redefine the default minimum set around oss:AbortMultipartUpload. In this skill, the default least-privilege path stays anchored on bucket discovery, bucket metadata verification, and prefix-scoped upload/list/read actions. Multipart-cleanup permissions are follow-up work only when the user explicitly asks for them.
Execute, don't just document. Run each step's commands directly in the environment. Do not only write solution documents or scripts — actually execute
aliyun version,aliyun configure list,aliyun ossutil cp, etc. against the live environment.Extract
RegionId,BucketName,TargetOssPrefix,LocalSourcePath,Schedule,MaxAge,OperatingSystem, andBucketAlreadyExistsfrom the user's request. Only ask the user if a required parameter is genuinely missing.
[aliyun CLI]#bash
aliyun version
aliyun configure list
aliyun configure ai-mode enable
Verify that:
aliyun version is >= 3.3.3If the version is too low or aliyun is missing, see references/cli-installation-guide.md. Do not work around a missing CLI by switching to standalone ossutil or aliyun ossutil sync.
[aliyun CLI]#Always start by checking the candidate bucket inventory:
bash
aliyun ossutil api list-buckets --output-format json \
--read-timeout 60 --connect-timeout 30 \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload
If BucketAlreadyExists=yes, verify the selected bucket explicitly:
bash
aliyun ossutil stat "oss://${BucketName}" --region "${RegionId}" --output-format json \
--read-timeout 60 --connect-timeout 30 \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload
Cross-region note: When the active CLI profile's region (shown by
aliyun configure list) differs from the target bucket'sRegionId, you must add--region "${RegionId}"tostat,ls, andcpcommands. Using--endpointalone is insufficient because the request signing region must also match. The--regionflag overrides both the endpoint and the signing region in a single step.
What to confirm:
RegionIdIf BucketAlreadyExists=no, use the check-then-act idempotent pattern:
list-buckets (above) to confirm the bucket truly does not exist in the account — if it already exists, skip creation and go directly to stat verification.stat to verify:bash
aliyun ossutil stat "oss://${BucketName}" --region "${RegionId}" --output-format json \
--read-timeout 60 --connect-timeout 30 \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload
Optional recommendation for recurring backup scenarios:
Keep aliyun ossutil as the canonical surface for upload and verification commands such as cp, ls, and stat. For bucket creation, follow the existing creation flow already documented by this skill instead of inventing a new command family here. Do not fabricate success, extra deployment files, or fake local artifacts just to cover a missing prerequisite.
[aliyun CLI / integrated ossutil]#Use the official data-plane command family for the actual scheduled upload job through aliyun ossutil:
bash
aliyun ossutil cp "${LocalSourcePath}" "oss://${BucketName}/${TargetOssPrefix}" \
-r -u \
--max-age "${MaxAge}" \
--region "${RegionId}" \
--read-timeout 300 --connect-timeout 30 \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload
Key rules for this command:
-u is mandatory: uploads only when the target object is missing or the source file is newer than the existing OSS object-r -u --max-age must stay together as the canonical flag set--region "${RegionId}" ensures both endpoint and signing region are correct--read-timeout 300 --connect-timeout 30 prevents the command from hanging indefinitely; adjust --read-timeout upward for very large files if needed-f only for unattended runs (cron, Task Scheduler, CI)LocalSourcePath (never ~)TargetOssPrefix without a leading /ossutil, aliyun ossutil sync, or Cache-Control metadata rewritesIf TargetOssPrefix is empty, use oss://${BucketName}/ (with trailing slash). Otherwise use oss://${BucketName}/${TargetOssPrefix} after prefix normalization.
If
LocalSourcePathdoes not exist in the current environment (e.g., container or CI runner), create it under the current working directory with a small test file, then run the upload command against it and verify withaliyun ossutil ls. This proves the upload path works end-to-end. Do not skip the upload test just because the directory is absent — create it and validate connectivity, permissions, and command correctness:bash
mkdir -p "${LocalSourcePath}" && echo "test" > "${LocalSourcePath}/test.txt" aliyun ossutil cp "${LocalSourcePath}" "oss://${BucketName}/${TargetOssPrefix}" \ -r -u --max-age "${MaxAge}" --region "${RegionId}" \ --read-timeout 300 --connect-timeout 30 \ --user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload aliyun ossutil ls "oss://${BucketName}/${TargetOssPrefix}" --region "${RegionId}" \ --read-timeout 60 --connect-timeout 30 \ --user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload
[aliyun CLI + OS-local]#Minimal script template:
bash
#!/usr/bin/env bash
set -euo pipefail
ALIYUN_BIN="${ALIYUN_BIN:-aliyun}"
LOCAL_SOURCE_PATH="${LocalSourcePath}" # MUST be an absolute path, never use ~
BUCKET_NAME="${BucketName}"
TARGET_OSS_PREFIX="${TargetOssPrefix#/}"
MAX_AGE="${MaxAge}"
REGION_ID="${RegionId}"
LOG_FILE="${OSS_SYNC_LOG:-$HOME/oss-sync.log}"
READ_TIMEOUT="${READ_TIMEOUT:-600}"
CONNECT_TIMEOUT="${CONNECT_TIMEOUT:-30}"
# --- Input validation ---
[[ "${BUCKET_NAME}" =~ ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$ ]] || { echo "ERROR: Invalid BucketName: ${BUCKET_NAME}" >&2; exit 1; }
[[ "${REGION_ID}" =~ ^[a-z]{2}-[a-z]+(|-[0-9]+)$ ]] || { echo "ERROR: Invalid RegionId: ${REGION_ID}" >&2; exit 1; }
[[ "${MAX_AGE}" =~ ^[0-9]+[dhm]$ ]] || { echo "ERROR: Invalid MaxAge: ${MAX_AGE}" >&2; exit 1; }
[[ "${TARGET_OSS_PREFIX}" =~ ^[A-Za-z0-9/_.-]*$ ]] || { echo "ERROR: Invalid TargetOssPrefix: ${TARGET_OSS_PREFIX}" >&2; exit 1; }
[[ "${LOCAL_SOURCE_PATH}" == /* ]] || { echo "ERROR: LocalSourcePath must be absolute: ${LOCAL_SOURCE_PATH}" >&2; exit 1; }
TARGET_URI="oss://${BUCKET_NAME}/"
if [ -n "${TARGET_OSS_PREFIX}" ]; then
TARGET_URI="oss://${BUCKET_NAME}/${TARGET_OSS_PREFIX}"
fi
"${ALIYUN_BIN}" ossutil cp "${LOCAL_SOURCE_PATH}" "${TARGET_URI}" \
-r -u -f \
--max-age "${MAX_AGE}" \
--region "${REGION_ID}" \
--read-timeout "${READ_TIMEOUT}" --connect-timeout "${CONNECT_TIMEOUT}" \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload >> "${LOG_FILE}" 2>&1
Note: The
-fflag is included in the script template because the script is intended for unattended cron/Task Scheduler execution where interactive prompts must not block the job. The--regionflag is preferred over--endpointbecause it sets both the endpoint and signing region correctly, which is required when the CLI profile's default region differs from the target bucket's region.
[OS-local]#Linux/macOS cron:
For the default Linux/macOS path in this skill, keep cron / crontab as the documented scheduler surface. Do not silently swap the answer to launchd unless the user explicitly asks for a launchd-specific variant.
If
crontabis not found: In container or minimal environments,crontabmay not be pre-installed. Install thecroniepackage first:
- CentOS/Alibaba Cloud Linux/RHEL:
yum install -y cronie- Debian/Ubuntu:
apt-get install -y cronIf
systemctl start crondfails (e.g., no systemd in containers), you can still add cron entries viacrontab— the cron daemon is not strictly required for entry registration, only for actual execution. In such cases, document the cron entry for the user to deploy on their production host, and do not let the missing daemon block the rest of the workflow.
bash
crontab -e
Example entry (use echo ... | crontab - for non-interactive installation):
cron
0 3 * * * /usr/local/bin/oss-sync-upload.sh >> /var/log/oss-sync-cron.log 2>&1
Windows Task Scheduler via local CLI:
bat
schtasks /Create /SC DAILY /ST 03:00 /TN "OSS Scheduled Sync" /TR "C:\tools\oss-sync-upload.bat"
Label this step clearly as OS-local. It is not an Alibaba Cloud API action. Keep the scheduler output minimal and directly actionable; do not explode this step into extra README files, XML exports, PowerShell wrappers, demo payloads, or other auxiliary artifacts unless the user explicitly asks for them.
[aliyun CLI / integrated ossutil]#Always run this verification after any upload (including test uploads from Step 3):
bash
aliyun ossutil ls "oss://${BucketName}/${TargetOssPrefix}" --region "${RegionId}" \
--read-timeout 60 --connect-timeout 30 \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload
Confirm that the expected objects appear under the target prefix. Do not skip this step — it proves end-to-end connectivity and permissions.
If the user wants a manual visual check, label it clearly as [Manual/Console] and confirm the target prefix in the OSS Console.
Always state these limitations when relevant:
aliyun ossutil. This skill stays on the aliyun CLI surface and does not require a separate standalone ossutil installation.Use references/verification-method.md as the authoritative checklist.
Minimum pass conditions:
aliyun configure list shows a valid profile.aliyun ossutil cp --help succeeds.aliyun ossutil cp ... -r -u --max-age ... --region ... command completes without permission or endpoint errors.aliyun ossutil ls ... --region ... shows the expected uploaded objects under the confirmed prefix.-u, meaning it uploads only when the target object is missing or the local source file is newer than the existing OSS object.crontab -l or Task Scheduler history/query, or is documented for the user when crontab is not available in the current environment.Cleanup is optional because this skill is intended for recurring sync, but test artifacts and scheduler entries can be removed safely.
Linux/macOS cron [OS-local]:
crontab -eWindows Task Scheduler [OS-local]:
bat
schtasks /Delete /TN "OSS Scheduled Sync" /F
Optional OSS test cleanup [aliyun CLI / integrated ossutil]:
bash
aliyun ossutil rm "oss://${BucketName}/${TargetOssPrefix}test-object.txt" --region "${RegionId}" \
--read-timeout 60 --connect-timeout 30 \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-oss-manage-cron-upload
Do not delete the bucket or production objects unless the user explicitly asks for that cleanup scope.
Disable AI safety mode [aliyun CLI]:
After all tasks are completed, disable AI safety mode to restore normal CLI behavior:
bash
aliyun configure ai-mode disable
See references/related-apis.md for the command inventory, OSS capability notes, and validation notes. That file is reference metadata only.
aliyun for pre-checks, command discovery, bucket verification, and integrated aliyun ossutil cp for the actual scheduled upload.--region "${RegionId}" on all aliyun ossutil commands ( stat, cp, ls, rm) to ensure both endpoint and signing region are correct. This is especially important when the CLI profile's default region differs from the target bucket's region. Do not rely on --endpoint alone, as it does not override the signing region and will fail with "Invalid signing region in Authorization header" errors when using STS tokens across regions.aliyun version and aliyun configure list on the target machine before live execution.~/.aliyun/config.json, and never replace the credential gate with inline secret handling.LocalSourcePath in commands and scripts. Do not use ~ (tilde) because it may not expand inside quoted strings, causing "not a directory" errors.-f flag to prevent interactive confirmation prompts from blocking unattended execution.ReferenceDescriptionreferences/cli-installation-guide.mdRequired CLI installation guide copied from the creator skill assetreferences/verification-method.mdPre-check, upload, scheduler, and manual verification checklistreferences/related-apis.md``aliyun and integrated ossutil command inventory with OSS API mappingreferences/ram-policies.mdLeast-privilege RAM policy guidance for verification and uploadreferences/acceptance-criteria.mdCorrect and incorrect command patterns for this scenario