Quote:
Originally Posted by Xeratul
Hi,
The goal is simple, making a backup using simple bash tools (actually linux sys tools such as cp and cpio) for:
/harddrive => /backups/hardrive
I would be glad if a solution such as --delete could be proposed in order to mirror the current state of the /harddrive.
The aim is to avoid rsync use.
Would you have any simple solution that might be proposed?
thank you in advance
|
The first thing that you always should do when trying to write a script or program is to break down your problem into smaller sub-problems.
For example, your backup problem can at first be divided into two sub-problems:
- the actual backup
- the removal of files that no longer exist on the source
You can break down these sub-problem into smaller problems:
Backup:
- find files which have to be backed up (pretty easy if the backup is scheduled on a timely basis, for example every 24 hours, just find all files with a newer creation/modification time, find can do that)
- copy them with preserving the path (the --parents option of cp can do that, can also be done using tar or cpio)
Removal:
- find all files that are potential candidates for removal in the backup folder (files that are younger than the last backup have just been copied by you, so you need only to check files that are older)
- check if those files exist under the same relative path in the source directory (a case for Bash parameter substitution and the test command), if not delete the file in the backup
With breaking the problem down this way it shouldn't be that hard to come up with a Bash script for the wanted functions.