2

I am using ubuntu 12.04 TLS in which i have a git repository in a specific directory, what i am trying is to take the scheduled backup of the repository and place it in specific directory that can be mailed.

In the process i get to know to find all the git repository in specific directory by googling i found this below command

find /home/mysys/D/ -name .git -type d -prune

but it contain the path as

/home/mysys/D/testing/.git

which list all the git files associated in the directory and it is working, but what i need to execute git bundle create directoryname.bundle --all to make it more automated in which i tried the following

find /home/mysys/D/ -name .git -type d -prune -exec git bundle create test.bundle --all {} \;

The above bash script returns

fatal: Invalid gitfile format: .git

How to do this to make it work robust.

Thanks in Advance.

1 Answer 1

2

You want to be in the git-controlled directory when git bundle is executed, so use find ... -execdir ... \;

find /home/mysys/D/ -type d -name .git -prune -execdir git bundle create backup.bundle --all \;

That will create a backup.bundle in all these directories. From there you can move those, or process them with more scripting. But the bundling side of things is handled.

9
  • Thanks oli it is working is there a way to make the basename as bundlename along with today date is it possible? Mar 31, 2016 at 12:33
  • if the folder name as test then test_31mar2016.bundle like that? Mar 31, 2016 at 12:34
  • 1
    Sure, wangle your execdir statement around to something like: sh -c 'git bundle create $(basename $(dirname {}))"_"$(date +"...")".bundle" --all'. (this needs work, ie to format the date)
    – Oli
    Mar 31, 2016 at 12:39
  • 1
    Needs a bit more tweaking. $(basename $(readlink -f {}/..)) should get your the parent directory name.
    – Oli
    Mar 31, 2016 at 13:03
  • 1
    Sure but you'd need to wrap it in another shell. You'd be better off writing a standalone bash script that calls your find command, an then calling that script from cron.
    – Oli
    Mar 31, 2016 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .