Testing our solution

Let's see whether our two programs play nicely together. You may want to open two terminal windows for this, since we'll be running two programs.

We have already added some paths to the database, so let's use backup to see them:

./backup -db="./backupdata" list

You should see the two test folders; if you don't, refer to the Adding paths section:

= ./test [Not yet archived]
= ./test2 [Not yet archived]

In another window, navigate to the backupd folder and create our two test folders, called test and test2.

Build backupd using the usual method:

go build -o backupd

Assuming all is well, we can now start the backup process, being sure to point the db path to the same path as we used for the backup program and specifying that we want to use a new folder called archive to store the ZIP files. For testing purposes, let's specify an interval of 5 seconds in order to save time:

./backupd -db="../backup/backupdata/" -archive="./archive" - interval=5s

Immediately, backupd should check the folders, calculate the hashes, note that they are different (to Not yet archived), and initiate the archive process for both folders. It will print the output that tells us this:

Checking...
Archived 2 directories

Open the newly created archive folder inside backup/cmds/backupd and note that it has created two subfolders: test and test2. Inside these are compressed archive versions of the empty folders. Feel free to unzip one and see; nothing very exciting so far.

Meanwhile, back in the terminal window, backupd has been checking the folders for changes again:

Checking...
  No changes
Checking...
  No changes

In your favorite text editor, create a new text file inside the test2 folder, containing the word test, and save it as one.txt. After a few seconds, you will see that backupd has noticed the new file and created another snapshot inside the archive/test2 folder.

Of course, it has a different filename because the time is different, but if you unzip it, you will notice that it has indeed created a compressed archive version of the folder.

Play around with the solution by taking the following actions:

  • Change the contents of the one.txt file
  • Add a file to the test folder too
  • Delete a file
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.187.210