Compress, encrypt, and copy data to offsite server #
Under Windows, I was using AxCrypt and WinSCP from the context menu to compress, encrypt, and send data to an offsite server. Under OS X, I am now using a simple bash command list to achieve the same thing faster and with greater compression:
$ /Applications/file/BetterZip.app/Contents/Resources/7z a -mx9 -pSECRET -mhe ~/Desktop/file.7z ~/Documents/file.ext && scp -P 2012 ~/Desktop/file.7z user@example.com:/home/ && rm ~/Desktop/file.7z
Let's break down what's happening here:
- /Applications/file/BetterZip.app/Contents/Resources/7z Call the 7-Zip file archiver contained in BetterZip (which I happened to have from a MacUpdate Promo Bundle). There are several other Mac binaries available or you can download and compile from source.
- a Add file(s) to archive
- -mx9 Maximum ("Ultra") compression
- -pSECRET Set password to SECRET
- -mhe Encrypt archive headers (i.e., filenames will be encrypted also)
- ~/Desktop/file.7z Name of archive to create or add files to
- ~/Documents/file.ext File to compress and encrypt
- && Execute next command only if previous command returns an exit status of zero (i.e., wait for command to complete successfully before proceeding)
The next section assumes public-key authentication has been configured (see part 2 of Hardening SSH and Mounting Remote Filesystem in OS X Finder via SSHFS for more information):
- scp Secure copy command
- -P 2012 Connect via port 2012
- ~/Desktop/file.7z Local file to copy
- user@example.com:/home/ Remote username and domain followed by directory where file will be copied to
These next two steps are optional:
- && Execute next command only if previous command returns an exit status of zero (i.e., wait for command to complete successfully before proceeding)
- rm ~/Desktop/file.7z Delete 7z archive from local computer
Notes:
- As the command list is rather long, you may want to make a permanent alias in OS X by adding a line like this one to your ~/.bash_profile:
alias bkup='/Applications/file/BetterZip.app/Contents/Resources/7z a -mx9 -pSECRET -mhe ~/Desktop/file.7z ~/Documents/file.ext && scp -P 2012 ~/Desktop/file.7z user@example.com:/home/ && rm ~/Desktop/file.7z'
- After adding the above line, you can load your .bash_profile without logging out: $ source ~/.bash_profile
and list current aliases with: $ alias -p
- Archive all text files in current directory: $ 7z a file.7z *.txt
- Extract all files from file.7z: $ 7z x file.7z
/mac | Sep 19, 2009
Subscribe or visit the archives.