You are not logged in.

#1 2019-01-06 19:34:04

Only1KW
Member
Registered: 2015-12-14
Posts: 17

Scripted OS backup

I am trying to implement the following workflow:

  1. Automate backup of OS partition on boot drive to a different drive on a regular basis (weekly?)

  2. Backups run on a regular basis for some unknown period of time

  3. Boot drive fails

  4. Purchase new drive with storage space >= size of backed up OS partition

  5. Restore latest image to new drive

  6. Plug drive into computer (if not already) and power computer on.

  7. Computer automatically boots to same state it was at at the time of the last backup.

Reasoning: I probably spent weeks trying to install and configure Arch the first time, and I don't remember all the configuration changes I made any more.  I don't have weeks to redo it all, and feel that backing up and restoring the whole thing will be quicker.

I've searched for ways to do this, but everything I find says there is absolutely no way to safely back up a running OS, which I know is not true because this is done by VMWare VMotion and IBM Live Partition Mobility.  I don't even have a strict requirement to have the OS running at the time, as long as I can automate the process, because I know I won't take the time to manually do this once a week, and even if I was willing to, the work involved in backing up will probably end up being more than recovering afterwards with just a simple rsync script copying individual files and then re-configuring everything from scratch.

Any suggestions?

Offline

#2 2019-01-06 19:42:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,531
Website

Re: Scripted OS backup

Only1KW wrote:

I've searched for ways to do this, but everything I find says there is absolutely no way to safely back up a running OS

Where the hell are you searching?
https://lmddgtfy.net/?q=backup%20!aw


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2019-01-07 04:12:43

Jclifton44
Member
From: United States
Registered: 2017-07-07
Posts: 32

Re: Scripted OS backup

Make it a cron job. You'd need to delete each backup after you make the newest so you don't run out of space.

It may be a better idea to write scripts you can run to configure the arch installation from it's initial state.

For example, this script installs a postfix server and configures a user:
https://github.com/jclifton44/shell-scr … Postfix.sh
It only works on Ubuntu. It could be modified to work with Arch or any other distribution.

Last edited by Jclifton44 (2019-01-07 04:14:20)


"... a high signal to noise ratio..."

Offline

#4 2019-01-07 04:16:03

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: Scripted OS backup

You really shouldn't be publicising your scripting until you have cleaned it up: `cat file | grep ...` Really? Grep, like practically every other utility, takes a file name as an argument.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2019-01-07 04:16:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,531
Website

Re: Scripted OS backup

Jclifton44 wrote:

You'd need to delete each backup after you make the newest so you don't run out of space.

Proper use of incremental backups with rsync (as described in the wiki) would mitigate this for the most part.  You can delete really old backups as needed, but with incrementals you can keep a very large number of snapshots.

EDIT a specific example of JWRs advice:

# YOUR VERSION
cat /etc/s-nail.rc | grep "^set emptystart"
if [ $? -ne '0' ];
then
	echo "set emptystart" >> /etc/s-nail.rc
fi
# BETTER VERSION
grep -q '^set emptystart' /etc/s-nail.rc || echo 'set emptystart' >> /etc/s-nail.rc
# ANOTHER OPTION
sed -i '/set emptystat/d;$aset emptystat' /etc/s-nail.rc

But that whole thing is for a debian-based distro, so clearly not an example of what to use here.  EDIT 2: I see you have *several* such blocks all working on the same file!  A single sed command can specify all three options in the config file.

Last edited by Trilby (2019-01-07 04:33:53)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2019-01-07 05:41:28

waitnsea
Member
From: France
Registered: 2013-02-10
Posts: 67

Re: Scripted OS backup

Trilby wrote:
Jclifton44 wrote:

You'd need to delete each backup after you make the newest so you don't run out of space.

Proper use of incremental backups with rsync (as described in the wiki) would mitigate this for the most part.  You can delete really old backups as needed, but with incrementals you can keep a very large number of snapshots.

Hi,
BORG could make perfectly the job

Last edited by waitnsea (2019-01-07 05:41:54)

Offline

#7 2019-01-07 07:34:51

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Scripted OS backup

The (I think) classic discussion on using rsync for snapshotting: http://www.mikerubel.org/computers/rsync_snapshots/

Of course, a number of filesystems these days support native snapshotting facilities, but using software RAID would be an even better move.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB