Scripting backup of file naming?

Giorgos Keramidas keramida at ceid.upatras.gr
Mon Jun 7 12:09:17 PDT 2004


On 2004-06-07 11:01, Bart Silverstrim <bsilver at chrononomicon.com> wrote:
> *problem; on server1, I'm going to have two directories: ~/archive and
> ~/workingdir.  I want the scp to move the files from server2 to
> ~/workingdir, tar and zip them as a file name with a date attached
> (like backup06072004.tgz) to make the filename distinctive, then move
> that file from ~/workingdir to ~/archive.  The filename would need to
> be distinctive both to allow for reference when needing to restore a
> snapshot and also to keep the archives from overwriting each other when
> moved over.
>
> Is there a simple way to do this with a script running from cron?

Yes, there is.  Write a shell script that contains all the command lines
you want to run and use cron to call it periodically.

As for the dated filenames, it's easy:

	#!/bin/sh

	outfilename="backup-"$(date '+%y-%m-%d-%H%M')".tar.bz2"
	echo "Saving files into: ${outfilename}"
	tar cvf - path/to/dir/1  path/to/dir/2 | \
	    bzip2 -9c -> "${outfilename}"

This should be almost all you need.



More information about the freebsd-questions mailing list