jaxon_b
asked on
Backup script to run on mac
I have on batch file on my pc to backup everything from my pc to my external drive. I am using xcopy example (xcopy c:\users\Administrator\des ktop\*.* /D /E /C /Y e:\backup\Administrator\de sktop\) How would I do this on a mac for the different folder directories?
rsync -a /Users/Administrator/Deskt op /VolumeNameOfBackup/Backup Folder
rsync -a /Users/Administrator/Docum ents /VolumeNameOfBackup/Backup Folder
repeat for any folder in the home directory that you want to backup.
This will create a folder in BackupFolder called Desktop and recursively copy all files and folders in archive mode.
Subsequent use will only copy files that have been changed.
Open terminal and type "man rsync"
You will see all of the options for rsync.
In a nutshell rsync -options sourcedir destinationdir
rsync -a /Users/Administrator/Docum
repeat for any folder in the home directory that you want to backup.
This will create a folder in BackupFolder called Desktop and recursively copy all files and folders in archive mode.
Subsequent use will only copy files that have been changed.
Open terminal and type "man rsync"
You will see all of the options for rsync.
In a nutshell rsync -options sourcedir destinationdir
ASKER
I am having a hard time trying to understand the rsync process with a external drive. Can I have the script on the desktop to run (like a batch) or can it automatic detect a mounted drive then run?
Yes you could write a script similar to a batch script. OS X is built on UNIX so there are various scripting languages you could use. Most common is bash.
here is a sample script.
Open a text editor create the following:
The first line is essential and must be line 1.
Once the file is saved you must make it executable. Open terminal and type
Or, you can have the file open in terminal (right click>Open with.../Utilities/Terminal .app).
Put backup.sh on your desktop and double click to run.
here is a sample script.
Open a text editor create the following:
#!/bin/sh
rsync -a /Users/Administrator/Desktop /VolumeNameOfBackup/BackupFolder
rsync -a /Users/Administrator/Documents /VolumeNameOfBackup/BackupFolder
Save this as backup.shThe first line is essential and must be line 1.
Once the file is saved you must make it executable. Open terminal and type
chmod +x /pathtofile/filename
Now in terminal you can execute to script by typing it's location eg. /pathtofile/filename.sh and the script will run.Or, you can have the file open in terminal (right click>Open with.../Utilities/Terminal
Put backup.sh on your desktop and double click to run.
ASKER
Is there anyway that the profile name can be read as wild card so it can apply to multiple machine names without being specific?
If you want the script to be clickable without having to right-click, then click open, rename it to backup.command or create a link to backup.sh named backup.command and put it on the desktop.
ln -s ~/backup.sh ~/Desktop/backup.commnad
The default mount point of your disk is in /Volumes/. OSX automounts external disks and remote shares there.
You could also semi-automate your script with a check for the external disk and copy only when it detects the external disk, then schedule it to run periodically.
You could make it automatic, but that requires a little more work. I don't suggest this unless you have time to learn a bit more about the underpinnings. You'll have to write a launch daemon to watch the folder or usb event. You can to look in /System/Library/LaunchDaem ons/ for examples, such as com.apple.backupd-auto.pli st or com.apple.usbd.plist, to create the launchd and use it to call the script you've made. I suggest copying the plist files out of there to your local folder to work on, so you don't accidentally trash any of the critical system files. Don't change an existing launch daemon, create a new one with a new name and register it.
ln -s ~/backup.sh ~/Desktop/backup.commnad
The default mount point of your disk is in /Volumes/. OSX automounts external disks and remote shares there.
You could also semi-automate your script with a check for the external disk and copy only when it detects the external disk, then schedule it to run periodically.
#!/bin/bash
if [ -d "/Volumes/NAME_OF_EXTERNAL_DISK" ]; then
rsync -a /Users/AdminAccountName/AdminAccountName/Desktop /Volumes/NAME_OF_EXTERNAL_DISK/AdminAccountName/Desktop
fi
You could make it automatic, but that requires a little more work. I don't suggest this unless you have time to learn a bit more about the underpinnings. You'll have to write a launch daemon to watch the folder or usb event. You can to look in /System/Library/LaunchDaem
Jaxon, Not sure what you are asking. The scripts we have suggested are not machine specific. As long as the external disk is the same (or at least the same name) for each computer, the scripts would run fine on each. If by profile name you mean username. Yes you could have the script get the current logged in user. Or you could backup up the whole /Users folder catching all of the users that have logged into the computer.
Are you wanting to backup up multiple computers or multiple users on a single computer - or both?
Are you wanting to backup up multiple computers or multiple users on a single computer - or both?
ASKER
both
You should copy the script below and change the folder on the external disk for each computer in case you have duplicate account names. That way you don't wipe data between systems.
You don't need a wildcard to copy all user data.
To back up multiple user folders:
You don't need a wildcard to copy all user data.
To back up multiple user folders:
#!/bin/bash
if [ -d "/Volumes/NAME_OF_EXTERNAL_DISK" ]; then
rsync -a /Users/ /Volumes/NAME_OF_EXTERNAL_DISK/Users_Computer1/
fi
If you really only want Desktop items, then you'd do something like this:if [ -d "/Volumes/NAME_OF_EXTERNAL_DISK" ]; then
cd /Users; for USER_LIST * ; do rsync -a /Users/$USER_LIST/Desktop /Volumes/NAME_OF_EXTERNAL_DISK/Users_Computer1/$USER_LIST/Desktop
fi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
On Mac you would just use Time Machine. If you want the command line, use cp to copy.
Open in new window
You would use rsync if you want to do robocopy.exe and not copy files that have already been copied.
Open in new window