Refactor code struture

This commit is contained in:
sevichecc 2023-04-18 01:09:37 +08:00
parent f72209fc63
commit 3b1c7a4a8d
Signed by untrusted user who does not match committer: SevicheCC
GPG key ID: C577000000000000

View file

@ -1,31 +1,32 @@
#!/usr/bin/expect #!/usr/bin/expect
set ACCESS_KEY_ID "YOUR_ACCESS_KEY_ID" set ACCESS_KEY_ID "YOUR_ACCESS_KEY_ID"
set SECRET_ACCESS_KEY "YOUR_SECRET_ACCESS_KEY" set SECRET_ACCESS_KEY "YOUR_SECRET_ACCESS_KEY"
set PASSWORD "YOUR_PASSWORD" set PASSWORD "YOUR_PASSWORD"
set timeout -1 set timeout -1
# Function to handle authentication
proc authenticate {} {
global ACCESS_KEY_ID SECRET_ACCESS_KEY PASSWORD
expect "ID"
send "$ACCESS_KEY_ID\r"
expect "Secret"
send "$SECRET_ACCESS_KEY\r"
expect "password"
send "$PASSWORD\r"
}
# Run duplicacy backup command
spawn duplicacy backup -threads 4 spawn duplicacy backup -threads 4
authenticate
expect "completed"
expect "ID" # Run duplicacy prune command (optional)
send "$ACCESS_KEY_ID\r" spawn duplicacy prune -keep 7:30
authenticate
expect "Secret" # Allow user interaction after script completion
send "$SECRET_ACCESS_KEY\r" interact
expect "password"
send "$PASSWORD\r"
##### (optional) Keep a revision every 7 days for revisions older than 30 days
# expect "completed"
# spawn duplicacy prune -keep 7:30
# expect "ID"
# send "$ACCESS_KEY_ID\r"
# expect "Secret"
# send "$SECRET_ACCESS_KEY\r"
# expect "password"
# send "$PASSWORD\r"
expect eof