{"id":367,"date":"2012-11-22T14:32:52","date_gmt":"2012-11-22T15:32:52","guid":{"rendered":"http:\/\/www.tamats.com\/blog\/?p=367"},"modified":"2012-11-22T19:05:06","modified_gmt":"2012-11-22T20:05:06","slug":"virtual-private-servers-and-backup-script-in-python","status":"publish","type":"post","link":"https:\/\/www.tamats.com\/blog\/?p=367","title":{"rendered":"My own host and a backup script in python"},"content":{"rendered":"<p>Some time ago I decided that instead of sharing some space in a hosting service to have all my websites I was going to rent my own private server. I could had plugged one old machine to the network at home and save the money but if I have to pay every month a fee I&#8217;m sure I will make good use of it.<\/p>\n<p>Now two years later the experience have proved to be great, I manage remotely my own Ubuntu machine (my knowledge in Unix systems have improved a lot), my own http server (nginx), I have services running (GIT, some node.js scripts) and I&#8217;m hosting several websites from some of my friends.<\/p>\n<p>I&#8217;m using <a href=\"http:\/\/linode.com\">linode.com<\/a> (great service) for a virtual machine of 256 MB of RAM (more than what I need), it costs me 20 Euros per month which I think is fair.<\/p>\n<p>Thanks to that I&#8217;ve been able to code all kind of crazy ideas which it would had been impossible without my own remote machine, and I encourage to all the webmasters to give it a try one day to pass to a next level.<br \/>\n<!--more-->Something I miss when working in Unix is a good backup service, so today I made my first step into the backups system of my host.<\/p>\n<p>I have made a little script to manage the backups, I wanted to do it in Javascript using Node.js but I end up using Python which has better modules for file handling.<\/p>\n<p>Now when I am in some random folder I can call this command &#8211; backmeup name * &#8211; it copies all files from this folder matching the wildcard to the backups\/$data\/name folder. A simple way to have some backups of folders of great importance.<\/p>\n<p>Here is the script:<\/p>\n<pre lang=\"python\">#!\/usr\/bin\/python\r\n\r\nprint \"backing you up, bro\"\r\nbackups_folder = \"\/home\/tamat\/backups\/\"\r\n\r\nimport os,sys,glob,datetime,getpass\r\nfrom subprocess import call\r\n\r\nwildcard = \"*\"\r\n\r\nif len(sys.argv) &lt; 2:\r\n    print \"sorry bro, I need a backup name\"\r\n    sys.exit(0)\r\n\r\nbackup_name = sys.argv[1]\r\n\r\nfiles = sys.argv[2:]\r\n\r\nif len(files) == 0:\r\n    print \"no files to backup, justsayin'\"\r\n    sys.exit(0)\r\n\r\nnow = datetime.datetime.now()\r\nfolder_name = backups_folder + now.strftime(\"%Y-%m-%d\") + \"\/\"\r\n\r\nif not os.path.isdir(folder_name):\r\n    os.mkdir( folder_name )\r\n\r\nif backup_name != \"\" and backup_name != \"this\":\r\n    folder_name = folder_name + backup_name + \"\/\"\r\n\r\nif not os.path.isdir(folder_name):\r\n    print \"creating folder, yo: \" + backup_name\r\n    os.mkdir( folder_name )\r\n\r\ntext_file = open(folder_name + \"backup.log\", \"a\")\r\ntext_file.write(\"saved from '\"+os.getcwd()+\"' by '\"+getpass.getuser()+\"' on \" + now.strftime(\"%Y-%m-%d %H:%M\") + \"\\n\")\r\ntext_file.close()\r\n\r\nfor file in files:\r\n\tprint \" + \" + file\r\n\tcall([\"cp\",\"-R\",file, folder_name])\r\n\r\nprint \"didit\"<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Some time ago I decided that instead of sharing some space in a hosting service to have all my websites I was going to rent my own private server. I could had plugged one old machine to the network at home and save the money but if I have to pay every month a fee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,4,21],"tags":[],"class_list":["post-367","post","type-post","status-publish","format-standard","hentry","category-coding","category-python","category-webdevelopment"],"_links":{"self":[{"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=367"}],"version-history":[{"count":4,"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/367\/revisions"}],"predecessor-version":[{"id":371,"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/367\/revisions\/371"}],"wp:attachment":[{"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tamats.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}