Created
December 24, 2013 12:46
-
-
Save stasiek/8112836 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # OSX RAMdisk with rsync auto backup | |
| # Variables config | |
| ramdisk="name" | |
| path1="source/path/1" | |
| path2="source/path/2" | |
| path3="source/path/3" | |
| rsyncinterval="300" # autobackup interval | |
| ramdisksize="4096" # RAMdisk size in MB | |
| path1name=`basename "$path1"` | |
| path2name=`basename "$path2"` | |
| path3name=`basename "$path3"` | |
| cd "$(dirname "$0")" | |
| while :; do | |
| echo "Creating RAMdisk." | |
| let r=($ramdisksize\*2048) | |
| diskutil erasevolume HFS+ ""$ramdisk"" `hdutil attach -nomount ram://$r` | |
| echo "RAMdisk created." | |
| echo "Copying directories into $ramdisk" | |
| cp -r "$path1" /Volumes/"$ramdisk" | |
| echo "$path1 copied." | |
| cp -r "$path2" /Volumes/"$ramdisk" | |
| echo "$path2 copied." | |
| cp -r "$path3" /Volumes/"$ramdisk" | |
| echo "$path3 copied." | |
| echo "All directories copied" | |
| echo "Initialising rsync autosave loop" | |
| while :; do | |
| sleep "$rsyncinterval"; | |
| screen -p 0 -S ramdisk_autobackup -X stuff "`echo -e "autosaving RAMdisk => drive \r"`"; | |
| rsync -r /Volumes/"$ramdisk"/"$path1name" "$path1"; | |
| rsync -r /Volumes/"$ramdisk"/"$path2name" "$path2"; | |
| rsync -r /Volumes/"$ramdisk"/"$path3name" "$path3"; | |
| done & echo "Autosave complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment