What is the problem you are having with rclone?
I'm running rclone with cron as a nightly backup of my NAS to s3. The actual behavior of rclone copying and creating backup files works exactly the way I want it to, no problems there.
Now I'd like to get email notifications any time the backup sends new files to or modifies files on s3, but no emails when nothing changes. My cron is setup to send an email only if the command being run generates any output on stdout. Thus, I would like for rclone to generate stdout that lists files transferred or modified on s3, and be completely silent if nothing changes. I almost have it working exactly the way I want, except that when nothing changes rclone prints out There was nothing to transfer
, and I would rather have it not print anything. How do I suppress that line of text, but still be able to see the list of transferred or modified files when work happens?
I followed this post to generate the list of synced files.
Run the command 'rclone version' and share the full output of the command.
rclone v1.58.1
- os/version: ubuntu 14.04 (64 bit)
- os/kernel: 3.16.0-77-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.17.9
- go/linking: static
- go/tags: none
Which cloud storage system are you using? (eg Google Drive)
s3
The command you were trying to run (eg rclone copy /tmp remote:tmp
)
s3backup.sh
DEST=aws:mybucket
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DATE=`date +"%FT%H-%M-%S"`
SOURCE_DIR=/data
DEST_DIR="$DEST/last_snapshot"
BACKUP_DIR="--backup-dir=$DEST/archive/$(date +%Y)/$DATE"
CONFIG="--config $DIR/rclone.conf"
OPTIONS="--fast-list --no-update-modtime --links --stats=0 --stats-one-line -v --s3-no-check-bucket --exclude-from $DIR/rclone-exclude.txt $@" # add --progress when run manually
rclone $CONFIG sync $OPTIONS $SOURCE_DIR $DEST_DIR $BACKUP_DIR
The rclone config contents with secrets removed.
[aws]
type = s3
provider = AWS
access_key_id = <removed>
secret_access_key = <removed>
region = us-east-1
acl = private
server_side_encryption = AES256
storage_class = STANDARD
stdout when I add a file
This works the way I want it to, and it prints what I want it to print!
$ /bin/bash s3backup.sh
2022/05/14 19:09:35 INFO : Media/Videos/beebooboobop.mp4: Copied (new)
stdout when I deleted some files
This works the way I want it to, and it prints what I want it to print!
$ /bin/bash s3backup.sh
022/05/14 19:45:54 INFO : Media/Pictures/Photos/Albums/stars/029-DSC07604.tif: Copied (server-side copy)
2022/05/14 19:45:54 INFO : Media/Pictures/Photos/Albums/stars/029-DSC07604.tif: Deleted
2022/05/14 19:45:54 INFO : Media/Pictures/Photos/Albums/stars/029-DSC07604.tif: Moved into backup dir
2022/05/14 19:45:55 INFO : Media/Pictures/Photos/Albums/stars/024-DSC07599.tif: Copied (server-side copy)
2022/05/14 19:45:55 INFO : Media/Pictures/Photos/Albums/stars/024-DSC07599.tif: Deleted
2022/05/14 19:45:55 INFO : Media/Pictures/Photos/Albums/stars/024-DSC07599.tif: Moved into backup dir
2022/05/14 19:45:56 INFO : Media/Pictures/Photos/Albums/stars/033-DSC07628.tif: Copied (server-side copy)
2022/05/14 19:45:56 INFO : Media/Pictures/Photos/Albums/stars/033-DSC07628.tif: Deleted
2022/05/14 19:45:56 INFO : Media/Pictures/Photos/Albums/stars/033-DSC07628.tif: Moved into backup dir
2022/05/14 19:45:57 INFO : Media/Pictures/Photos/Albums/stars/036-DSC07632.tif: Copied (server-side copy)
2022/05/14 19:45:57 INFO : Media/Pictures/Photos/Albums/stars/036-DSC07632.tif: Deleted
2022/05/14 19:45:57 INFO : Media/Pictures/Photos/Albums/stars/036-DSC07632.tif: Moved into backup dir
stdout when I don't change anything
This is where the problem is - while it correctly does nothing, it prints this line and I would rather it just return without printing anything!
$ /bin/bash s3backup.sh
2022/05/14 20:23:53 INFO : There was nothing to transfer
Thanks in advance!