Samstag, 9. Juni 2018

How I backup my Synology NAS using rsync

I might be a bit oldfashioned, but I prefer to use my onw backup solution on my NAS rather than relying on a tool by the supplier. I use two external Harddrives, which I exchange in intervals. To backup my content on it, I use good old rsync. Note that for this approach to work, you should turn on the "User-Home-Service", otherwise, there is no home directory for admin. To install the script, ssh to the NAS with the admin user: ssh admin@yoursyno.domain Then change to root using sudo -i. The backupscript is simple. Note that it just creates an archive on the disk. Since my target disk currently is on NTFS, I use raw rsync. At a later stage, I will change to rsnapshot. (Which requires you to install perl on the NAS first.) Without further ado, here is my script:

I added this in /etc/crontab to start the backup daily. Note how I use the flock command to ensure that only a single instance of the backup is running. It is important to put the lockfile in a location other than /tmp.

Finally, I need to make sure that the logs do not overflow. To that end, I created this file in /etc/logrotate.d

Montag, 13. November 2017

Service Now Script Includes: Make sure to convert object references to values

Because I want to have a clean design, I try to use System properties. This gives me flexibility and clarity over strange literals like

var group_sys_id = "690acf664fc51200d4a679a18110c746" ;
Instead I write
var group_sys_id = gs.getProperty("inc.assignment.group.default") ;
Even if you have never seen one of my instances, it will be clear from the code above that the property defines the sys_id of the default assignment group.

Sometimes, you have to deal with a list of properties and you might not know initially how many there are. An example we encountered: the customer wants to send out notifications for expiring firewall rules. Currently, there are notifications to send 30, 14 and zero days prior to expiry.
The worst solution for this would be to add 3 columns to the table where said firewall rules are stored and put the actual notification dates there.
This is bad on many levels:

  • It is a violation of good database design practise (Violation of the 1st Normal Form)
  • It leads to a loss of flexibility (only an admin can add more notifications)
  • You assume that there will always be three notifications
Therefore, I create a naming convention and use it to name a couple of system properties. In my case 
  • sc.firewall.notify.days.1
  • sc.firewall.notify.days.2
  • sc.firewall.notify.days.3
sc because this concerns the service catalog. The values just contain integers (30, 14, 0).
All very well, now I just need a function (in a script include) to return these values.

How not to do it

My first attempt looked simple enough: But when I tested it (you always do that, right?), I was surprised (running this in a background script).

var Toolbox = new Toolbox_Functions()
var res= Toolbox.getPropertyList("sc.firewall.notify.")
gs.print(res);
[0:00:00.002] Script completed in scope global: script
*** Script: sc.firewall.notify.3,sc.firewall.notify.3,sc.firewall.notify.3
Whoa what's that?

Fixing the Problem

This is not a problem with Service Now, but a problem with JavaScript (or even Object-Oriented programming). The reason for this behaviour is that property_gr.name (line 23) contains an object reference and it will always point to the last element read (that is why we get the third entry three times)
GlideRecord to the rescue: Service Now has added the function getValue(), well, to get the value (instead of the default object reference).
Another approach would be to use

arr.push(property_gr.name.toString());

or

arr.push(String(property_gr.name));


Recommended Reading

Samstag, 15. April 2017

Book review - The Peter principle by Laurence J Peter and Raymond Hull

This is the first installment of a new section of my blog - the review of vintage books.

“The Peter Principle” is known by many, but few have taken the time to actually look at the book that defines the principle. This volume, written in 1969 by journalist Raymund Hull as a popular account of the work of Laurence J. Peter is a fascinating piece of work. Much to my surprise, this book is very tongue-in-cheek and full of self-criticism.

On the surface, the book is based on this idea:

Every employee tends to be promoted until the individual level of incompetence is reached.

Starting from this statement, a wohle new science (the so-called “hierarchology”) is developed and many interesting “real-life” examples are presented.

Great examples include the “flying T-Formation”, where 23 vice presidents lead 3 divisions, the “free floating apex” where “a director is in charge of a non-existing department” or the most modern hierarchy of all where the computer replaces all lower ranks and only managers would remain.

Many examples can be found in real life - my favorite example is the “lateral arabesque”, where a manager is moved out of the way and given a much longer, important-looking job title.

The authors also provide guidance on how to avoid the trap of the principle - for example by developing some eccentric traits, such as leaving all drawers on ones office open when leaving in the evening.

Ultimately, the book has a far wieder scope - Peter and Hull are concerned about mankind as such and urge the reader to prevent our race from begin promoted to far (into oblivion). Here, they speak of “life competence”, which we as a race must retain.

A weak point of the book is its latent sexism. In this aspect, the book seems dated, while the book is modern in most other aspects.

The end of the book is symptomatic of the theme: Peter asks if somebody is willing to fund a professors post for him (because he has proven competent at the PhD level). This humorous self-criticism is a very strong aspect of this book.

Samstag, 19. März 2016

Code to check if your Email Adresses where compromised

Yesterday, the Swiss Governmental CERT has published a press release stating that more than 6000 Email Accounts where compromised. They offer a tool to check if your address is compromised, which is, in my option very well designed. (Some people asked why the site is hosted at Cloudflare - the CERT claims thy did that for DDoS prevention. The Databse supposedly is based in Switzerland). To check an Email-Address is contained in the database, the site creates a SHA-265 Hash of the lowercase Emailadress and transfers this. This ensures that no real Emailadresses are transferred. The downside is that this way, it is not so simple to check a lot of Emailadresses (like all of your company). Below, I provide a simple Powershell script to check a list of Emailadresses. As an input, it requires a simple CSV of the format Email me@email.com I throttled the script quite a bit to be nice.

What to do if an address of yours was compromised?

This could mean two things: either the actual Email-account is compromised (really bad) or some web account where this Email address was used is compromised (badness depends on if the service is critical AND if the same password was used elsewhere). I recommend the following:


  • Immediately Change the Password of said Email-Account
  • Change the password of all accounts where the Email address is used as a password
To do this properly, you need a list of your accounts and their passwords  - not on paper, but in a Passwordsafe like Keepass. A Passwordsafe also includes a strong password generator - each account must have its own password!

Donnerstag, 10. März 2016

Moving Contents of subdirectories in a Windows batch or on the command line

Imagine you encounter a directory scruture like this:
In each of these yearly folders, there are many subfolders. My goal was to flatten this structure so that all of these subfolders are in th current folder (in other words, one level higher that they are now). It turns out that this is not so easy in Windows because the command move does not intepret * to include folders. Superuser.com to the rescue! User Rik proposed this nifty solution that works like a charm:
 @echo off  
 for /d %%d in ("*") do (  
  for /d %%e in ("%%d\*") do (  
   move "%%e" .  
  )  
 )  
Note: this code only works for subdirectories. If the yearly folders directly contain files, they will not be copied. In this case, use this code:
 @echo off  
 for /d %%d in ("*") do (  
  for /d %%e in ("%%d\*") do (  
   move "%%e" .  
  )  
  move "%%d\*" .  
 )  
Thanks a lot, Rik!

Mittwoch, 7. Januar 2015

Open Access gains momentum

In a recent publication, Lib4RI, the joint library of the Research Institutes within the ETH Domain, has compiled evidence to show that Open Access is gaining momentum. To recap, here is what Open Access is all about:
Open access (OA) means unrestricted online access to peer-reviewed scholarly research. Open access is primarily intended for scholarly journal articles, but is also provided for a growing number of theses, book chapters, and scholarly monographs. Open access comes in two degrees: gratis open access, which is free online access, and libre open access, which is free online access plus some additional usage rights. These additional usage rights are often granted through the use of various specific Creative Commons licenses. Only libre open access is fully compliant with definitions of open access such as the Berlin Declaration on Open Access to Knowledge in the Sciences and Humanities.

(Open access. (2015, January 6). In Wikipedia, The Free Encyclopedia. Retrieved 10:44, January 7, 2015, from http://en.wikipedia.org/w/index.php?title=Open_access&oldid=641177048)
On the one hand, the article acknowledges that OA is seen as a new market, in which both new and old players thrive. Also, scientific and porfessional societies (such as IEEE or ACM) play an important role to propagate OA. Not to be neglected is the power of funding agencies, where for example the EU plays an important role.

Mittwoch, 2. Juli 2014

A completely new approach to where we come from

We learn in modern school that apes and human being share a common ancestor. (Many people misquote this as "human beings are descendants of the apes").

It turns out that this notion  recently got competition by a revolutionary new hypothesis which at first sounds quite strange, but then is really compelling. As Eugene M. McCarthy explains comprehensively on his page, he proposes the hypothesis that humans are a so-called backcrossed hybrid. So rather than slowly evolving from a single species, according to this hypothesis, human beings might be a cross of two completely different species which then repeatedly mated with one of the ancestors. One of these ancestors he calls chimpanzees (however he states "here, I use the term chimpanzee loosely to refer to either the common chimpanzee or to the bonobo, also known as the pygmy chimpanzee; the specific roles of these two rather similar apes within the context of the present hypothesis will be explained in a subsequent section".

After having read the extremely interesting book "Sex at dawn" by Ryan and Jetha (I know the title is cheesy), I think it is prudent to believe that the bonobo is one of the ancestors. Then he addresses the question of which animal might be the second ancestor. He does this by meticulously listing (a subset) of the features found in humans but not in chimpanzees and then seeks to find an animal that has all of these features.

 Lets try it:

  • Intelligent
  • Naked skin
  • Eyes in different colors, including blue
  • Protruding nose (made of cartilage)
  •  Eyebrows and Eyelashes present
  • Good swimmer
  • Eats a large variety of food
What animal comes to mind?
Let's say we have a bit of a difficult relationship to this animal.
But - we use its organs (for example skin or heart) to replace human organs.
Many religions forbid to eat the flesh of this animal.
And - last but not least - its the name of a song by Pink Floyd.


And if you look at such a cute specimen - don't you see something of us there?

This hypothesis causes some strange sensations, I have to admit it.
But it really makes a lot of sense. Here is just a selection of observations Eugene McCarthy shares:

  • Humans are not very fertile, especially male sperm is often degenerate. This is common for hybrid mammals
  • Pigs are indeed very intelligent
  • Pigs have a cleft lip - something that never occurs in apes but may occur in humans

I will continue to think about this - to end for now this nice poem:
Thank the Pig by Gene McCarthy

Not everyone will say it's true,
But pigs are creatures much like you.
We ape an ape in many ways,
Yet pig distinctions win our praise.