aliyunpan

repository·main·Indexed 26 days ago

https://github.com/tickstep/aliyunpan

A command-line interface (CLI) tool for interacting with Aliyun Drive (Aliyunpan). It supports file operations including uploading, downloading, syncing, and managing cloud directories. The tool features an interactive CLI mode and a dedicated Docker image (tickstep/aliyunpan-sync) for automated backup and synchronization tasks with support for exclusive and incremental policies.

Tokens
20.7K
Snippets
52
Records
132
Agent score
89%

What's inside aliyunpan

  1. Use the Sync and Backup feature

    main

    The sync and backup feature allows you to back up local files to the cloud (upload mode) or download cloud files to your local machine (download mode).

    Backup Strategies:

    • exclusive: Performs an exact one-to-one backup. Files deleted in the source directory will be deleted in the target directory.
    • increment: Performs incremental backups. New or modified files are synced, but files in the target directory that are not in the source are preserved.

    Note: The target cloud directory should be used exclusively for this sync task to avoid conflicts.

  2. Run aliyunpan-sync in Docker

    main

    You can run the sync service using Docker or Docker Compose.

    Required Environment Variables for Docker Run:

    • ALIYUNPAN_PAN_DIR: Target cloud directory.
    • ALIYUNPAN_SYNC_MODE: upload or download.
    • ALIYUNPAN_SYNC_POLICY: exclusive or increment.
    • ALIYUNPAN_SYNC_DRIVE: backup or resource.
    • ALIYUNPAN_SYNC_LOG: true or false.

    Docker Compose Configuration: Use the following environment variables in your docker-compose.yml:

    • ALIYUNPAN_DOWNLOAD_PARALLEL: Download concurrency.
    • ALIYUNPAN_UPLOAD_PARALLEL: Upload concurrency.
    • ALIYUNPAN_DOWNLOAD_BLOCK_SIZE: Download block size (KB).
    • ALIYUNPAN_UPLOAD_BLOCK_SIZE: Upload block size (KB).
    • ALIYUNPAN_SYNC_CYCLE: infinity (loop) or onetime.
    • ALIYUNPAN_LOCAL_DELAY_TIME: Delay in seconds to detect local file changes (useful for files being actively written).
    version: '3'
    services:
      sync:
        image: tickstep/aliyunpan-sync:<tag>
        container_name: aliyunpan-sync
        restart: always
        volumes:
          - ./data:/home/app/data:rw
          - /your/file/path/for/aliyunpan_config.json:/home/app/config/aliyunpan_config.json
        environment:
          - TZ=Asia/Shanghai
          - ALIYUNPAN_DOWNLOAD_PARALLEL=2
          - ALIYUNPAN_UPLOAD_PARALLEL=2
          - ALIYUNPAN_DOWNLOAD_BLOCK_SIZE=1024
          - ALIYUNPAN_UPLOAD_BLOCK_SIZE=10240
          - ALIYUNPAN_PAN_DIR=/my_sync_dir
          - ALIYUNPAN_SYNC_MODE=upload
          - ALIYUNPAN_SYNC_POLICY=increment
          - ALIYUNPAN_SYNC_CYCLE=infinity
          - ALIYUNPAN_SYNC_DRIVE=backup
          - ALIYUNPAN_SYNC_LOG=true
          - ALIYUNPAN_LOCAL_DELAY_TIME=3
  3. Install aliyunpan via apt (Ubuntu/Deepin)

    main

    Use this method for systems with the apt package manager, such as Ubuntu or Deepin. Currently supports amd64 and arm64 architectures.

    sudo curl -fsSL http://file.tickstep.com/apt/pgp | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/tickstep-packages-archive-keyring.gpg > /dev/null && echo "deb [signed-by=/etc/apt/trusted.gpg.d/tickstep-packages-archive-keyring.gpg arch=amd64,arm64] http://file.tickstep.com/apt aliyunpan main" | sudo tee /etc/apt/sources.list.d/tickstep-aliyunpan.list > /dev/null && sudo apt-get update && sudo apt-get install -y aliyunpan
  4. Login to Aliyunpan

    main

    To use the service, you must log in via a web browser. This requires two steps: an authorization step and a QR code scan. Run the login command within the interactive CLI to generate the authentication link. Note that the link is valid for only 5 minutes.

    aliyunpan > login
  5. Use Multi-User Download (--md)

    main

    To maximize download speeds, use the --md flag. This requires multiple accounts to be logged in, all having access to the same file at the same path within the same drive (Backup or Resource). The download speed is aggregated across all active users.

    aliyunpan download /我的资源/1.mp4 -md
  6. Limit the number of files downloaded per execution

    main

    You can control the number of files downloaded during a single download command execution by implementing the downloadFilePrepareCallback and downloadFileFinishCallback functions.

    To achieve this, use PluginUtil.KV to track the count of files processed within a specific downloadActionId and use PluginUtil.HashTool.md5Hex on the driveFilePath to track the status of individual files.

    Logic flow:

    1. In downloadFilePrepareCallback, check if the current count for the downloadActionId has reached your desired limit. If so, set downloadApproved to "no".
    2. If the limit is not reached, mark the file as "downloading" in the KV store.
    3. In downloadFileFinishCallback, mark the file as "finish" in the KV store to prevent re-downloading in future runs.
    function downloadFilePrepareCallback(context, params) {
        var result = {
            "downloadApproved": "yes",
            "localFilePath": ""
        };
    
        // Limit for this download action
        const maxCountOfDownloadAction = 3;
    
        // Only process files
        if (params["driveFileType"] != "file") {
            return
        }
    
        // Get current count for this download action
        var keyOfThisDownloadAction = "download:" + params["downloadActionId"];
        var valueOfThisDownloadAction = PluginUtil.KV.getString(keyOfThisDownloadAction);
        if (valueOfThisDownloadAction == "") {
            valueOfThisDownloadAction = "0";
        }
        var countOfThisDownloadAction = parseInt(valueOfThisDownloadAction);
        if (countOfThisDownloadAction >= maxCountOfDownloadAction) {
            // Limit reached, skip remaining files
            result["downloadApproved"] = "no";
            return result;
        }
    
        // Track individual file status
        var keyOfThisDownloadFile = "file:" + PluginUtil.HashTool.md5Hex(params["driveFilePath"]);
        var valueOfThisDownloadFile = PluginUtil.KV.getString(keyOfThisDownloadFile);
        if (valueOfThisDownloadFile == "finish") {
            // Already finished, skip
            return result;
        }
        PluginUtil.KV.putString(keyOfThisDownloadFile, "downloading");
    
        // Increment and save count
        countOfThisDownloadAction += 1;
        PluginUtil.KV.putString(keyOfThisDownloadAction, String(countOfThisDownloadAction));
    
        return result;
    }
    
    function downloadFileFinishCallback(context, params) {
      var keyOfThisDownloadFile = "file:" + PluginUtil.HashTool.md5Hex(params["driveFilePath"]);
      console.log(keyOfThisDownloadFile)
      PluginUtil.KV.putString(keyOfThisDownloadFile, "finish");
    }
  7. Set up JavaScript plugins

    main

    The program supports JavaScript plugins to customize behaviors during upload, download, sync, and delete operations.

    Installation Steps

    1. Locate the sample files in the plugin/js directory of the program installation.
    2. Copy the desired sample file and change its extension from .sample to .js. Available samples:
      • download_handler.js.sample $\rightarrow$ download_handler.js
      • upload_handler.js.sample $\rightarrow$ upload_handler.js
      • remove_handler.js.sample $\rightarrow$ remove_handler.js
      • sync_handler.js.sample $\rightarrow$ sync_handler.js
      • token_handler.js.sample $\rightarrow$ token_handler.js
    3. If you have set the ALIYUNPAN_CONFIG_DIR environment variable, ensure the plugin folder is copied into that configured directory for the plugins to take effect.
  8. Install aliyunpan via yum (CentOS/RockyLinux)

    main

    Use this method for systems with the yum package manager, such as CentOS or RockyLinux. Currently supports amd64 and arm64 architectures.

    sudo curl -fsSL http://file.tickstep.com/rpm/aliyunpan/aliyunpan.repo | sudo tee /etc/yum.repos.d/tickstep-aliyunpan.repo > /dev/null && sudo yum install aliyunpan -y