Racer D
what?
in this howto I'd like to explain how to do backups of your files onto a samba share.
I will show you how to do this free, without the use of some programs you have to pay for. Instead I created a shell script to do this for you.
This should be all, now just wait till 5 AM and have your backups made
post any questions & suggestions to the script or the tutorial you might have
use at your own risk...
It worked for me, but I cannot guarantee it will work for you too.
--- script updated 24. 5. 04 (minor bugs) ---
I will show you how to do this free, without the use of some programs you have to pay for. Instead I created a shell script to do this for you.
- first of all, you need to have access to a samba share in your network. I hope you can figure how to do that on your own
- now open your Terminal.app (/Applications/Utilities/Terminal.app)
type in this commands (enter your admin password when prompted for it)
Code:sudo touch /usr/bin/mount sudo chmod +x /usr/bin/mount sudo pico /usr/bin/mount
next, paste this into terminal while your pico editor is opened (command+c / command+v)
Code:#! /bin/sh # a script to make backups onto a samba share # created and tested on MAC OS X 10.3 # # Author: Racer D <racer.d@email.si> # Date: 2004-05-24 # # ----- variables # where you would like to mount the shared drive mount_point=/Volumes/share # //username:password@server/share_name filesystem=//user:pass@192.168.1.1/share # where your files are at # must be full path (don't use ~ for home) local_dir=/Users/user/test # the same as local_dir but with \ infront of every / # also there has to be \/ at the end local_dir2="\/Users\/racer\/test\/" # in what direcotry under remote_dir would you like to keep backups backup_dir=backup # --------------- remote_dir=$mount_point/$backup_dir # uncomment if you want to do a full backup (not just files changed from last backup) # rm ~/Library/last_backup # making sure share is mounted, else mounting it if test -d $mount_point then mounted=no echo share already mounted. else mounted=yes echo mounting share... mkdir -v $mount_point mount_smbfs $filesystem $mount_point fi # create all necessary folders echo creating necessary folders... if ( ! test -d "$remote_dir" ) then mkdir "$remote_dir" fi if ( test -f ~/Library/last_backup ) then find -x $local_dir -type d -mindepth 1 -newer ~/Library/last_backup -print | sed s/$local_dir2// > ~/Library/backup_folders else find -x $local_dir -type d -mindepth 1 -print | sed s/$local_dir2// > ~/Library/backup_folders fi file=~/Library/backup_folders while read line do if ( ! test -d "$remote_dir/$line" ) then mkdir -v "$remote_dir/$line" fi done < $file rm ~/Library/backup_folders # listing all files to backup # if backup done before, list only files changed from last backup # else list all files echo listing files to backup... if ( test -f ~/Library/last_backup ) then find -x $local_dir -type f -newer ~/Library/last_backup -print | sed s/$local_dir2// > ~/Library/backup_files else find -x $local_dir -type f -print | sed s/$local_dir2// > ~/Library/backup_files fi # update the date when script was last run # this creates a file named "last_backup" in your Library. # Don't delete this file echo updating last run date... date > ~/Library/last_backup # copy the files echo copying the files... file=~/Library/backup_files while read line do cp -vf "$local_dir/$line" "$remote_dir/$line" done < $file rm ~/Library/backup_files # unmount the share if mounted before if [ "$mounted" = yes ] then echo unmounting share... umount $mount_point rm -rf $mount_point fi echo backup done.
press "ctrl + x" and then enter to save the file.
your basic backup script is now ready. type backup in terminal to backup your files.
what it does it is:
- first it checks if your samba share is mounted, else it mounts it
- then it finds all files that have been changed since the script was last run
- it copies all the changed files to your samba share.
- finally it removes all the temporary files and unmounts the share if it had to mount it before
+ it puts a file "last_backup" in your Library, which tells when the backup was last made. Do not delete this file unless you wish to do a full backup
* it does NOT though remove files on your share that do not exist in the original direcory anymore [anyone who knows how to do this, please post your suggestions]
- now, if you want the backups to be made automatically, you have to do this:
again, in your terminal, enter this command
Code:crontab -e
press "i". now type (or just paste) this line in
Code:0 5 * * * /usr/bin/backup
(see here for more info on how to automate your backups)
This should be all, now just wait till 5 AM and have your backups made
post any questions & suggestions to the script or the tutorial you might have
use at your own risk...
It worked for me, but I cannot guarantee it will work for you too.
--- script updated 24. 5. 04 (minor bugs) ---