Does anyone use rclone to sync their backups with their cloud provider? I can do this manually, but I’m looking to automate this with cron, so if anyone would care to share how they are doing this, it would be appreciated!
I do, but not using the tool within MiaB.
I have a remote server rsync the /home/user-data/backup/encrypted directory. This is done via a cron job on that server set to run an hour after MiaB’s daily maintenance.
Unfortunately, rsync doesn’t work with my cloud storage, whereas rclone does.
OOPS! My bad … too early in the morning, not enough coffee - or something like that. I read the title as Rsync, not Rclone.
Maybe if you have some other device that can work with
rsync, have it retrieve the records from MiaB and then it’s a part of your already configured backups.
Thanks, but I’m specifically interested in rclone as I already have it setup to sync my backups to my cloud drive. What I’m looking for is a way to automate this with cron. Unfortunately, it is not a straightforward (for me anyway) as running rsync with cron. Therefore, if anyone has any specific examples for rclone / cron and MIAB backups, I would appreciate it.
Does MiaB even support rclone natively as one of it’s backup options?
I am sorry - I am completely ignorant of rclone — I should look it up.
No. You need to install and configure rclone to work with your cloud service. Once configured, it works well. At the moment I need to ssh into the MIAB box and run the rclone command to sync the backups. I would rather cron ran this on a daily schedule after the duplicity backups have completed.
So do you already have rclone installed on your Miab doing backups - just manually run?
If that is the case, all you need to do is create a cron job as I do not see this will interfere in any way with the integral parts of MiaB.
Actually, I need to create a bash script and use cron to get this working. So far, I haven’t had much luck, which is why I am asking here if anyone has any experience of using rclone / cron with MIAB/duplicity backups.
I have used some of the examples located in /cron.d/ but I need to dig deeper into why it’s failing. If I find a solution I will post it. If someone else has a solution, I would love to hear it!
Honestly, I cheat and use Webmin to create the cron jobs!
As far as the bash script for the cron job to run … in my case, the command line argument is sufficient. With the obligatory she-bang, of course.
I run rclone from a cron job to sync just the MiaB backup files to a BackBlaze B2 bucket. When the job runs, it runs as the MiaB admin account, but then the job uses sudo to run rclone. I read up on best practices, and this seemed to be a solution, but would be interested in hearing others. Though the B2 bucket is private, its still nice to know the MiaB backup files are encrypted by MiaB. I do not back up the encryption key, but I do have a copy, securely stored offsite.
The cron job runs 30 mins after the MiaB backup. So far the amount of data synced to B2 has not exceeded the ‘free’ tiers on B2. Free being that we’re already paying BackBlaze for other features and the B2 bucket is freebie add-on, as long as its not going over the ‘free’ tier limits. The B2 bucket was easy to create and administer.
Yes, this is also my approach.
Would you mind sharing your cron (redacted if necessary)? I can’t get mine to work as expected.
First you have to modify your sudoer list so that your admin account’s chron job can run rclone without asking for a password. SSH into your Miab box and enter the command:
Once the visudo editor comes up, add the line:
<your_miab_admin_goes_here> ALL = (root) NOPASSWD: NOEXEC: /usr/bin/rclone sync*
This allows the chron job, running as your admin, the ability to exec the rclone sync command without a password. (To the professionals out there, is there a better way? The security hole this creates is just constrained to rclone sync, but I’d love there to be no hole, if possible.)
Then you need a crontab entry for your admin account. To edit the crontab:
sudo crontab -e -u <your_miab_admin_goes_here>
and the entry I used is:
30 4 * * * sudo /usr/bin/rclone sync /home/user-data/backup/encrypted remote:<your_b2_bucket_name> --config="/root/.config/rclone/rclone.conf" -v >> <path_of_your_choice>/rclone.log 2>&1
You will want to change the time when this runs to suit your needs. I do not have a cronjob to archive or trim the rclone.log. I manually trim it from time to time.
Since it sounds like B2 support is coming eventually to MiaB. I won’t be putting much further effort into this, like log rolling and archiving.
Perfect. Thanks for the pointers. I will make some adjustments to my settings.
An update on progress. I have this working reliably now. Here’s what I did.
- sudo visudo and add the details as described by @Dane (Thanks!)
- Create a script rclone-cloud.sh for executing the rclone sync. I placed it inside /home/username/mailinabox/management/ with the others created by the MIAB install. The script has the following code:
if pidof -o %PPID -x “rclone-cloud.sh”; then
/usr/bin/rclone sync /home/user-data/backup/encrypted remote:rclonebackup
Make sure rclone-cloud.sh is executeable:
chmod a+x rclone-cloud.sh
- Inside of /etc/cron.d/ create a file (rclone) with the following:
‘#’ Rclone scheduled sync for duplicity backups
16 4 * * * root /home/username/mailinabox/management/rclone-cloud.sh > /home/username/mailinabox/management/rclone.log 2>&1
If your rclone cloud setup was previously functioning manually, it should now be automated to backup your data. It may not be the most elegant hack, but it is working for me on 2 boxes.
thanks for sharing this with us. Exactly what I was looking for. Manually syncing is already working great. Now I want to automatize it with a cronjob. Unfortunately I am not sure what I have to put in for <your_miab_admin_goes_here>.
Using my MiaB admin user, which is my email address, is not working, as soon as I enter sudo crontab -e -u , I get the following error.
crontab: user `firstname.lastname@example.org’ unknown
Would be awesome if you or someone else (@digititus) can help me here.
Thanks in advance.
The admin account in this case is whatever account you setup up on your Linux box to administer MiaB. For example, on my box, it’s the account I use to install and update MiaB from the command line.
Thanks for your reply @Dane.
Can’t remember I had to setup a new user, so I guess I just used root, is there a recommendation not to do it with root?
When using root, do I have to edit visudo at all?