Page tree

Applies to VoipNow 3 and higher!

Time intervals are used in call filtering, call routing and also in charging plans. As a VoipNow administrator, you might need to export time intervals from one server to another, or from your account to another type of account - Service Provider, Organization, or User.

Defining time intervals for each server or for each account is an option, but it's time consuming. Instead, you could consider exporting, importing, or cloning them using a script that will save you time and effort. This article details how to work with the script.

Step-by-step guide

  1. Download the script.

    wget -O time_interval.pl https://raw.githubusercontent.com/4psa/voipnowtoolbox/master/time_interval.pl

  2. Install the needed Perl libraries.

    yum install perl-DBD-mysql perl-JSON

  3. Run the script. 

    perl time_interval.pl

    The available options will be displayed:


    Usage:
    Available options:
             Share a time interval with a different account
                    perl time_interval.pl share <time_interval_id> <client_id>
                    E.G.: perl time_interval.pl share 2 4
    
             Dump a time interval to a file
                    perl time_interval.pl dump <time_interval_id> <file_name or empty>
                    E.G.: perl time_interval.pl dump 2 afterhours
    
             Restore a time interval from a file
                    perl time_interval.pl restore <client_id> <file_name or empty>
                    E.G.: perl time_interval.pl restore 2 afterhours.json
    
    

Cloning time intervals on a different account

To clone an existing time interval on a different account, you need to know the ID of the time interval and the client ID of the destination account.

  perl time_interval.pl share <time_interval_id> <client_id>

Let's assume that the ID of the After Hours matching time interval created on the Admin level (Unified Communications >> Time Intervals) is 21, and let's copy the time interval on the Service Provider with ID  2.

 #> perl time_interval.pl share 21 2
TimeInterval AfterHours has been added on accountID: 2

Saving time intervals to a file

Assuming we want to create the same time interval on a different server, we need to save it to a file and restore it where it is needed.

In our example, we will use the same time interval with ID 21, used for After Hours matching, and we will run the following command:

#> perl time_interval.pl dump 21 afterhours
Time Interval AfterHours saved in afterhours.json

A new file similar to the one below (afterhours.json) will be created.  


{"mod_date":"2016-01-22 09:42:36","cr_date":"2015-11-10 12:11:09","client_id":"1","name":"AfterHours","data":[{"end_day":"31","time_interval_id":"21","month":"0","start_time":"00:00:00","end_time":"09:59:00","start_wkday":"2","end_wkday":"6","start_day":"1","td_id":"40"},{"end_day":"31","time_interval_id":"21","month":"0","start_time":"17:00:00","end_time":"23:59:00","start_wkday":"2","end_wkday":"6","start_day":"1","td_id":"41"},{"end_day":"31","time_interval_id":"21","month":"0","start_time":"00:00:00","end_time":"23:59:00","start_wkday":"7","end_wkday":"1","start_day":"1","td_id":"42"}],"timezone_id":"248","id":"21","type":"day"}

Restoring time intervals from file to an existing account

perl time_interval.pl restore <client_id> <file_name or empty>

Let's restore the time interval saved earlier to an existing account with ID 2. We will use the following command:

#> perl time_interval.pl restore 2 afterhours.json
TimeInterval AfterHours has been restored on accountID: 2

#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))

Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution 4.0 International.