2

What I'm trying to do backup?

  1. users home dir which include Desktop,Documents,Pictures, thunderbird which i need to backup of every user
  2. all users are in /home partition with there respective user name
  3. there are certain user AND files in /home which need to be exclude

What I've tried so far?

$ tar cvf home01 -T include /home  

NOTE: T which says only take that which are mention in file but does not work

$ find . \( -name \*Desktop -o -name \*Documents\* -o -name \*Pictures\*  -o -name \.thunderbird\*   \)  |
  xargs  tar zcvf /opt/rnd/home-$(date +%d%m%y).tar.zip 

NOTE: which takes backup of mention dir but it puts every users dir into one folder.

For example

$ ls -l /home

/home/user1/{Desktop,Documents,Pictures,.thunderbird}
/home/user2/{Desktop,Documents,Pictures,.thunderbird}
/home/user3/{Desktop,Documents,Pictures,.thunderbird}
/home/user4/{Desktop,Documents,Pictures,.thunderbird}
/home/user5/{Desktop,Documents,Pictures,.thunderbird}

From which I need to take only user1,user2,user3 home dir backup and exclude user4,user5

slm
  • 369,824

2 Answers2

2

You're nearly there! This should do:

tar zcvf /opt/rnd/home-$(date +%d%m%y).tar.zip */{Desktop,Documents,Pictures,.thunderbird} --exclude=user4 --exclude=user5
0

Here's a way to do it retaining your use of the find command:

$ find . \( -type d -path */Desktop -o -path */.thunderbird -o -path */Pictures \\) \! -path '*user[45]*' -prune | xargs  tar zcvf /opt/rnd/home-$(date +%d%m%y).tar.gz

Here's an easier version to look at:

$ find . \( -type d                                                   \
     -path */Desktop -o -path */.thunderbird -o -path */Pictures \)   \
     \! -path '*user[45]*' -prune                                     \
  | xargs  tar zcvf /opt/rnd/home-$(date +%d%m%y).tar.gz

This will find all the directories with the names in the first parens block \( ... \). These are the directories:

  • */Desktop
  • */thunderbird
  • */Pictures

The 2nd part excludes any paths that match the pattern *user[45]*. These pare pruned out of the list. Finally the resulting list of directories to passed to tar.

Additional things to consider

The above is NOT bullet-proof. It will exclude paths that include the string user4 or user5 in them. Also some care should be given to making sure that whatever you construct as a command can deal with spaces in filenames.

slm
  • 369,824