Copy timeshift snapshots [SOLVED]

If none of the more specific forums is the right place to ask

Copy timeshift snapshots [SOLVED]

Postby Scorpion » 2020-12-25 16:06

I use the /timeshift folder for the snapshots with rsync mode, and I would like to save a copy on /media/root/<external-drive>.

I found this script here https://forums.linuxmint.com/viewtopic. ... 9#p1496549:
Code: Select all
!/bin/bash
#update timeshift backup on external drive from snapshots on internal HD

sudo rsync -aAuHXvis --progress --delete --numeric-ids /media/root/LM18_timeshift/ /media/steve/Z97_LM_Backup/LM18.3_timeshift_backup/timeshift | tee ~/timeshift_backup_log

echo "Finished updating timeshift backup"

sleep 10
exit 0


Can I use that? What should I change?
Last edited by Scorpion on 2021-01-02 13:37, edited 3 times in total.
User avatar
Scorpion
 
Posts: 262
Joined: 2018-10-17 11:38

Re: Copy timeshift snapshots

Postby Head_on_a_Stick » 2020-12-25 17:43

Scorpion wrote:
Code: Select all
!/bin/bash

The shebang is incomplete and you don't need bash for that script so:
Code: Select all
#!/bin/sh

Scorpion wrote:
Code: Select all
sudo rsync -aAuHXvis --progress --delete --numeric-ids /media/root/LM18_timeshift/ /media/steve/Z97_LM_Backup/LM18.3_timeshift_backup/timeshift | tee ~/timeshift_backup_log

That command copies from /media/root/LM18_timeshift/ to /media/steve/Z97_LM_Backup/LM18.3_timeshift_backup/timeshift, which seems to be the opposite of your stated intention. And be careful with the trailing slash on the source directory:

http://qdosmsq.dunbar-it.co.uk/blog/201 ... -to-slash/

You don't need a pipe (|) and the tee command to direct output to a log file so replace the bit after the rsync command with
Code: Select all
> ~/timeshift_backup_log 2>&1

And it's probably best to flush the copy buffers after the command runs rather than wait 10 seconds (the Mint poster seems to think the sleep command is for 10 minutes but it isn't):
Code: Select all
sync

No need for the 'exit 0' line either, the script will have a zero exit status if it completes successfully anyway.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 13041
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Copy timeshift snapshots

Postby Scorpion » 2020-12-25 19:21

When I copied the script I missed the #.

Code: Select all
#!/bin/sh
#update timeshift backup on external drive from snapshots on internal HDD.

rsync -aAuHXvis --progress --delete --numeric-ids /timeshift/ /media/root/<external-drive>/timeshift-backup/pc-1 > ~/timeshift_backup_log 2>&1
echo "Finished updating timeshift backup"
synch

Is that right?
User avatar
Scorpion
 
Posts: 262
Joined: 2018-10-17 11:38

Re: Copy timeshift snapshots

Postby Head_on_a_Stick » 2020-12-25 19:32

There shouldn't be a "h" at the end of "sync" and the echo command should come after the sync command but otherwise it looks okay.

The rsync command will copy the contents of /timeshift/ to the /media/root/<external-drive>/timeshift-backup/pc-1/ directory but not the /timeshift/ directory itself, is that what you want?
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 13041
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Copy timeshift snapshots

Postby Scorpion » 2020-12-26 10:05

Yes, with more than 1 pc to backup I thought that would be redundant to have /media/root/<external-drive>/timeshift-backup/pc-1/timeshift.
Code: Select all
#!/bin/sh
#Update timeshift backup on external drive from snapshots on internal HDD.

rsync -aAuHXvis --progress --delete --numeric-ids /timeshift/ /media/root/<external-drive>/timeshift-backup/pc-1 > ~/timeshift_backup_log 2>&1
sync
echo "Finished updating timeshift backup"

Is now right?

Will TS be able to read the snapshots directly from the external drive?

To import them do I have to switch the directories in the rsync command?
User avatar
Scorpion
 
Posts: 262
Joined: 2018-10-17 11:38

Re: Copy timeshift snapshots

Postby Head_on_a_Stick » 2020-12-26 11:17

Scorpion wrote:Is now right?

Yes, that looks fine.

Scorpion wrote:Will TS be able to read the snapshots directly from the external drive?

No idea, sorry, I've never used Timeshift so I don't know how it works. I use my own backup script (via a systemd .timer unit).

Scorpion wrote:To import them do I have to switch the directories in the rsync command?

Yes but be sure to add a trailing slash after /media/root/<external-drive>/timeshift-backup/pc-1/ (unless you want to copy the pc-1/ directory itself to /timeshift/). Again, read the blog post to which I linked above to understand the importance of a trailing slash after the source directory when using the rsync command.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 13041
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Copy timeshift snapshots

Postby Scorpion » 2020-12-26 19:00

I have read the blog post, I implied that you have to add the necessary slashes:
Code: Select all
#!/bin/sh
#Restore timeshift backup from external drive on internal HDD.

rsync -aAuHXvis --progress --delete --numeric-ids /media/root/<external-drive>/timeshift-backup/pc-1/ /timeshift > ~/timeshift_backup_log 2>&1
sync
echo "Finished restoring timeshift backup"
User avatar
Scorpion
 
Posts: 262
Joined: 2018-10-17 11:38

Re: Copy timeshift snapshots

Postby Head_on_a_Stick » 2020-12-26 19:45

Image
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 13041
Joined: 2014-06-01 17:46
Location: /dev/chair


Return to General Questions

Who is online

Users browsing this forum: No registered users and 13 guests

fashionable