View Full Version : Script to Copy Home folders
applesaregood
Dec 6, 2007, 11:34 PM
Hello,
I have a server running 10.5. I have a hard drive of old Home folders for about 500 users that is from an older 10.3 server.
Users want access to their old files. Just copying over the Home folders works fine. The issue I'm having is I don't want the Library folder to be copied over, because it contains old preferences that are causing a problem.
So basically I have two folders that look like this:
/Users
jdoe
dsmith
bjones
/oldUsers
jdoe
dsmith
bjones
Within each Home folder for each user I have a Documents, Movies, Pictures, Desktop, and Library folder. I need to copy the contents of /oldUsers/jdoe to /Users/jdoe, but not the Library folder.
So I think I need a bash or AppleScript to do this. Programming really isn't my strong point and I'm just struggling reading sites on bash scripts.
Thanks all
casperghst42
Dec 7, 2007, 04:34 AM
Hi,
Have a look at 'rsync', if the uid/gid's are the same on both boxes, then this was what it was written to do.
Otherwise a shell script would probably make more sense than AppleScript.
Casper
Hello,
I have a server running 10.5. I have a hard drive of old Home folders for about 500 users that is from an older 10.3 server.
Users want access to their old files. Just copying over the Home folders works fine. The issue I'm having is I don't want the Library folder to be copied over, because it contains old preferences that are causing a problem.
So basically I have two folders that look like this:
/Users
jdoe
dsmith
bjones
/oldUsers
jdoe
dsmith
bjones
Within each Home folder for each user I have a Documents, Movies, Pictures, Desktop, and Library folder. I need to copy the contents of /oldUsers/jdoe to /Users/jdoe, but not the Library folder.
So I think I need a bash or AppleScript to do this. Programming really isn't my strong point and I'm just struggling reading sites on bash scripts.
Thanks all
satyam90
Dec 7, 2007, 08:11 AM
Use the following shell script.
Copy the script to "/"
Now while running script Enter source directory as "oldUsers" and destination directory as "Users"
Now it will copy all the files from source to destination leaving "Library"
#!/bin/sh
echo "Enter Source Directory"
read src
echo "Enter Destination Directory"
read dest
list(){
cd $1
for files in `ls -al | awk '{print $9}'`
do
if [[ -d $files ]] && [[ ! $files = "Library" ]] && [[ ! $files = "." ]] && [[ ! $files = ".." ]]
then
createdir=`echo $PWD | sed 's/'$src'/'$dest'/g'`
if [[ ! `ls $createdir/$files` ]]
then
mkdir -p $createdir/$files
fi
list $files
else
if [[ -f $files ]]
then
destdir=`echo $PWD | sed 's/'$src'/'$dest'/g'`
cp $files $destdir/$files
echo "#"
fi
fi
done
cd ..
}
list $src
HiRez
Dec 7, 2007, 10:26 PM
As an alternative, you could try an AppleScript to do it:
set sourceFolder to choose folder with prompt "Choose the source folder"
set destFolder to choose folder with prompt "Choose the destination folder"
set buttonReturned to (display dialog "Preparing to copy all subfolders and files of '" & (the name of (get the info for sourceFolder)) & "' to '" & (the name of (get the info for destFolder)) & "', except the 'Library' folder. Existing folders with the same name will be replaced. Make sure you know what you're doing before proceeding!")
if button returned of result is not "OK" then
quit
end if
tell application "Finder"
set subitems to every item in sourceFolder
repeat with anItem in subitems
if (the name of anItem as string) is not "Library" then
duplicate anItem to destFolder with replacing
end if
end repeat
end tellThat's totally untested, by the way. You might run into some permissions problems. At the very least, you'd have to be logged in as root to run it on user folders, I think.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.