mycpen

Mycpen

记录学习历程与受益知识
github
telegram
bilibili

08_Other-GitHub Actions Scheduled Execution Script, Backup to Upyun Cloud Storage

Introduction#

Using GitHub Actions to run Python FTP scripts on a schedule to achieve backups between Upyun Cloud Storage and GitHub repositories.

Repository example: https://github.com/mycpen/image_bed/tree/main/.github

Personal Example#

1. Add Workflow YML File#

Copy my YML example below; or follow this article, choose your desired workflow template, and then customize the content (Actions => New workflow = Choose a workflow).

My file path is .github/workflows/python-app.yml, and the content is as follows:

Parameter explanation:

  • cron: Defines the schedule for the workflow (with a delay), in Greenwich Mean Time (UTC). To convert to Beijing time, add 8 hours. Refer to: Cron format and settings in Actions, Handling timezone and caching issues in Actions

  • UPYUNUSERNAME, UPYUNPASSWORD, GITHUBUSERNAME, GITHUBEMAIL are custom Secrets constants.

    Constant NameExplanation
    UPYUNUSERNAMEUpyun FTP username, format "Operator Name/Service Name", refer to Upyun Video Tutorial, Upyun Documentation
    UPYUNPASSWORDUpyun FTP password, refer to the above
    GITHUBUSERNAMEGitHub account, e.g., mycpen
    GITHUBEMAILMain email associated with the GitHub account
  • ftp.py: Python script that synchronizes the file contents of the cloud storage and the repository using FTP.

  • git.sh: A script that pushes local changes to the remote, including commands like git add, git commit, git push.

2. Add Secrets Constants#

Add 4 Secrets constants: UPYUNUSERNAME, UPYUNPASSWORD, GITHUBUSERNAME, GITHUBEMAIL, with the same meanings as above.

image-20230417094207479

3. Grant Workflow Read and Write Permissions#

Refer to: https://blog.csdn.net/jj89929665/article/details/129817011

image-20230417095659542

4. Create Python Sync Script#

The script content is from: Python FTP Upload and Download Functionality.

The if statement at the end of the script declares the relevant paths and parameters.

My script path is .github/ftp.py, which synchronizes the repository's image/ directory with the Upyun cloud storage /image/ directory, and the content is as follows:

5. git.sh Push Changes#

I personally prefer to write the push command in a file and place it in the root directory of the repository.

Reference Articles#

  1. * Python script to get repository secrets in GitHub Actions
  2. * Create scheduled tasks using GitHub repositories for regular sign-ins and other services
  3. * FTP upload and download functionality implemented in Python
  4. * Fully automated deployment using GitHub Action
  5. * Upyun: How to upload files using FTP and API
  6. * Upyun: Create storage service and upload using FTP
  7. * Cron format and settings in GitHub/Gitlab Actions
  8. * Running Python scheduled tasks in GitHub Actions (handling timezone and caching issues)
  9. * Unable to access ‘https://github.com/x/‘: The requested URL returned error: 403 when running GitHub Actions
  10. * workflow_dispatch
  11. Using GitHub Actions for scheduled tasks
  12. Automatically pushing changes with GitHub+Action
  13. Automated packaging and deployment based on GitHub Action services
  14. Scheduled tasks based on GITHUB ACTION, truly fragrant!
  15. Scheduled execution of code in GitHub Actions: Daily scheduled Baidu link push
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.