Rclone Backup Before Shutdown

What is the problem you are having with rclone?

I have wrritten a Script to Backup to GDrive using RClone and got a Service File to run just before Shutdown. While trying the systemctl start Backup2GDrive.service the rclone bacup finishes quickly but when I Shutdown the shutdown process freezes and runs for long time. Sometimes it finishes but sometimes it never finishes.

Run the command 'rclone version' and share the full output of the command.

rclone 1.60.1

  • os/version: fedora 38 (64 bit)
  • os/kernel: 6.3.6-200.fc38.x86_64 (x86_64)
  • os/type: linux
  • os/arch: amd64
  • go/version: go1.19.3
  • go/linking: dynamic
  • go/tags: none

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone sync -P --fast-list --transfers 30 /home/user/Documents MyFedora_Documents: |

The rclone config contents with secrets removed.

[MyFedora_Documents]
type = drive
scope = drive
root_folder_id = [Intentionally Left Blank; It had a value]
token =  [Intentionally Left Blank; It had a value]
team_drive = 
client_id = [Intentionally Left Blank; It had a value]
client_secret = [Intentionally Left Blank; It had a value]

Script

 #!/bin/bash
 log=/home/user/Logs/GdriveBackup/GDriveBackup.txt
 printf "Sync Start Time - " > $log 
date >> $log
rclone sync -P --fast-list --transfers 30 /home/user/Documents MyFedora_Documents: |& tee -a $log
printf "Sync End Time - " >> $log 
date >> $log

SystemD File

[Unit]
  2 Description=RClone Shutdown Script
  3 DefaultDependencies=no
  4 Wants=network-online.target
  5 After=network-online.target
  6 Before=shutdown.target
  7
  8 [Service]
  9 Type=oneshot
 10 ExecStart=/home/user/Scripts/GDriveBackup.sh
 11 RemainAfterExit=yes
 12
 13 [Install]
 14 WantedBy=shutdown.target

I would say you have two choices:

  1. get into nitty gritty details of your OS shutdown workings and systemd to make sure that rclone systemd runs with all what it needs before proper shutdown begins - this has nothing to do with rclone BTW - it is your OS - your job to make program run before shutdown if you need it.

  2. forget shutdown system command and make your own shutdown script doing just two things - run rclone shutdown job and then do system shutdown - you can overwrite system shutdown commands in similar way how molly guard does. I even sort of remember you can get hooks into molly and modify behaviour - so it might be the easiest way.

option 1, already tried no use.
Let me try option 2.

1 Like

Definitely molly guard will work - and it is the easiest way as all is already done. You just plug in your script.

Will try this in the weekend.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.