# Backup/Restore user home dir using a script



## ccc (Jun 10, 2012)

Hi

I'm looking for scripts to Backup/Restore users' home directories.


----------



## jmccue (Jun 10, 2012)

Backup/restore can be as simple as a one line script.  I prefer tar(1), so this shows both backup/restore of /home:
`# cd / && tar -cf- home > "file or device"`
restore of /home:
`# cd / && tar -xf- < "file or device"`

Now depending how/were this data is physically stored, I usually pipe it through ccrypt.  Example:
`# cd / && tar -cf- home | ccencrypt -k "keyfile" > "file or device"`
of course make sure you keep the "keyfile" secret.  Note, you can also add a pipe through one of the compression utilities, example: gzip(1).

John


----------



## xy16644 (Jun 10, 2012)

I'm also looking for a backup script that will allow me to use dump on a weekly basis to backup my entire root file system, put the date in the filename and then have 4 weekly backups (so after the 5th week the first file is overwritten). Is this easily accomplished with a script and a cron job?


----------



## fluca1978 (Jun 11, 2012)

xy16644 said:
			
		

> Is this easily accomplished with a script and a cron job?



Yes it is. I don't see any problem here, except if you are backing up the / you will have recursion on the backup itself. Anyway, use date(1) to get the date (i-th day) and append it to a string that will be the filename, then tar(1) against such file. Place all in cron and it is done.


----------

