Ive been asked (Im thinking about doing this to my system too) to make a shell script that backups all files in x location to another location in y. The thing is that the backup must only be made if something has been changed. Example:
/x contains:
a (1 byte)
b (1 byte)
c (1 byte)
/y contains:
nothing
Ill put this script into crontab and everytime (say 3) it will execute. 3 arrives and there is nothing in /y and it will copy all files in /x to /y. To compensate space I think a good idea (this I will do to my script for my system) is gzip it all up. Anyways the current state (at 3:01) right now is.
/x contains:
a (1 byte)
b (1 byte)
c (1 byte)
/y contains:
a (1 byte)
b (1 byte)
c (1 byte)
Again 3 arrives and /y is the same as /x so nothing changes and nothing happens. But now, I open c in /x , type something inside and save it now it is:
/x contains:
a (1 byte)
b (1 byte)
c (2 bytes)
This changes it so now when the script excutes at 3 it has to delete everything in /y and rewrite it all over again with everything that is in /x (regardless that the other files havent changed).
How do I do this? I imagine something like doing a ls -a on /x and using cut to cut certain columns and seeing if it equals /y's files/file sizes but im not sure how to make a filename and file size relation or if it is even correct and a bit humiliating but I dont know how to use cut either (I know something but not enough to do this)
Question
powerade01
Ive been asked (Im thinking about doing this to my system too) to make a shell script that backups all files in x location to another location in y. The thing is that the backup must only be made if something has been changed. Example:
/x contains:
a (1 byte)
b (1 byte)
c (1 byte)
/y contains:
nothing
Ill put this script into crontab and everytime (say 3) it will execute. 3 arrives and there is nothing in /y and it will copy all files in /x to /y. To compensate space I think a good idea (this I will do to my script for my system) is gzip it all up. Anyways the current state (at 3:01) right now is.
/x contains:
a (1 byte)
b (1 byte)
c (1 byte)
/y contains:
a (1 byte)
b (1 byte)
c (1 byte)
Again 3 arrives and /y is the same as /x so nothing changes and nothing happens. But now, I open c in /x , type something inside and save it now it is:
/x contains:
a (1 byte)
b (1 byte)
c (2 bytes)
This changes it so now when the script excutes at 3 it has to delete everything in /y and rewrite it all over again with everything that is in /x (regardless that the other files havent changed).
How do I do this? I imagine something like doing a ls -a on /x and using cut to cut certain columns and seeing if it equals /y's files/file sizes but im not sure how to make a filename and file size relation or if it is even correct and a bit humiliating but I dont know how to use cut either (I know something but not enough to do this)
If someone could help thank you very much.
Link to comment
Share on other sites
8 answers to this question
Recommended Posts