Twitter Backup Shell Script
I put this together with help from a curl command posted by Damon. I have a "Full backup" shell script which is programmed to run once a week in the middle of the night with cron. It downloads full backups of my various online projects. I have now added these few lines so it also makes a backup of the last 500 twitter entries I have made. By replacing the [1-5] below with [1-32] you can download 3200 twitter entries, but I don't expect to exceed 500 twitter postings per week, so have decided to go easy on the twitter API.
Here is what I added to my backup shell script. Note you will have to change the directories to something that works for your setup and input your username and password for twitter.
#Save the date:
mydate_folder=`date +%Y.%m.%d`
#Create a new folder for today's backup:
mkdir ~/shell/backups/twitter/$mydate_folder
#Download 5 xml files of 100 twitter entries each from Twitter
curl -o ~/shell/backups/twitter/$mydate_folder/#1.xml -u username:password "http://twitter.com/statuses/user_timeline.xml?count=100&page=[1-5]"
#After the download tar and gzip the folder, and delete the original folder.
cd ~/shell/backups/twitter/
tar -czf $mydate_folder.tar.gz $mydate_folder
rm -rf ~/shell/backups/twitter/$mydate_folder
#Determine the size of the update to include in our log file:
mysize=`du -ks $mydate_folder.tar.gz | awk '{print $1}'`
#Add an entry to my log file (which I have already added entries to for other backups made tday)
echo "\nTwitter backed up. $mysize KB in size.\n" >> ~/shell/backups/log.txt
Any real shell programmer will probably see a hundred ways to make my script more efficient and discover possible problems. Contact me or twitter me at @kmlawson if you have a proposed improvement on this.
I put this together with help from a curl command posted by Damon. I have a "Full backup" shell script which is programmed to run once a week in the middle of the night with cron. It downloads full backups of my various online projects. I have now added these few lines so it also makes a backup of the last 500 twitter entries I have made. By replacing the [1-5] below with [1-32] you can download 3200 twitter entries, but I don't expect to exceed 500 twitter postings per week, so have decided to go easy on the twitter API.
Here is what I added to my backup shell script. Note you will have to change the directories to something that works for your setup and input your username and password for twitter.
#Save the date:
mydate_folder=`date +%Y.%m.%d`
#Create a new folder for today's backup:
mkdir ~/shell/backups/twitter/$mydate_folder
#Download 5 xml files of 100 twitter entries each from Twitter
curl -o ~/shell/backups/twitter/$mydate_folder/#1.xml -u username:password "http://twitter.com/statuses/user_timeline.xml?count=100&page=[1-5]"
#After the download tar and gzip the folder, and delete the original folder.
cd ~/shell/backups/twitter/
tar -czf $mydate_folder.tar.gz $mydate_folder
rm -rf ~/shell/backups/twitter/$mydate_folder
#Determine the size of the update to include in our log file:
mysize=`du -ks $mydate_folder.tar.gz | awk '{print $1}'`
#Add an entry to my log file (which I have already added entries to for other backups made tday)
echo "\nTwitter backed up. $mysize KB in size.\n" >> ~/shell/backups/log.txt
Any real shell programmer will probably see a hundred ways to make my script more efficient and discover possible problems. Contact me or twitter me at @kmlawson if you have a proposed improvement on this.