MBrownieBytes

A blog for software engineers, sys admins, devops, and the technically inclined.
How to guides, Tutorials, Tips and Tricks

  1. You are here:  
  2. Home

Blog

Mr. Roboto er Robocopy

Details
Published: 08 September 2018
  • backup

Robocopy, or "Robust File Copy", is a command-line directory and/or file replication command

From the source directory, find all shortcuts, and copy the shortcut contents to a destination directory [Wikipedia]

The most basic example
Copies files from Directory_A to Directory_B
> robocopy C:\Directory_A C:\Directory_B

Some info about Robocopy defaults:
It will only copy a file if the source and destination have different time stamps or different file sizes.
Also, data, attributes, and time stamps are copied. ACL permissions, owner information,

and auditing information are ignored. You can modify this behavior with the /copy flag.

Also note that the paths don't have a trailing backslash.

The following flurry of options will mirror files form a source directory to a destination directory, recursively, with status, summary and a log

> robocopy /b /e /xa:s /xjd /sl /a-:hs /mt /fp /mir /mt:2 /log:"C:/dev/transfer.log" /eta /tee /v /l "C:/dev/source" "D:/backup/dev/source"
 
  

And a translation of the options:

/b      - backup mode (there's a /zb option for restart mode, but it's a whole lot slower); overwrite acls

/e      - copies subdirectories (including empty directories) in addition to files

/xa:s   - exclude system files

/xjd    - exclude junction points

/sl     - copy symbolic links as links

/a-:hs  - remove hidden/system attributes from files

/fp     - full path of files in output

/mir    - MIRror a directory tree (equivalent to /e plus /purge)

/mt[:n] - Do multi-threaded copies with n threads (default 8)

/log:transfer.log - redirect output to file

/eta    - time remaining

/tee    - duplicate log to console window

/v      - verbose output + skipped

/l      - list files only (and not copy, delete, or time stamp)

Remove the option /l when ready to run

Note that the option /sl allows symbolic links to be copied, which is useful if you are using npm for node modules management or your git repository has symbolic links.

The options /eta, /tee, /v can be removed to minimize output to the console

You can also place the command within a bat file to run on double click, or some other event.

backup.bat:

echo "R: ramdrive -> C: backup"

robocopy /b /e /xa:s /xjd /sl /a-:hs /mt /fp /mir /mt:2 /log:"C:/backup/robocopy/transfer.log" /eta /tee /v /l "R:/code" "C:/backup/code"

pause

Microsoft documentation of Robocopy and other possible arguments

End of document. Thanks for reading.

PowerShell script to copy files based on shortcuts

Details
Published: 23 July 2018
  • powershell

From the source directory, find all shortcuts, and copy the shortcut contents to a destination directory

PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language. Wikipedia

# Get all shortcuts

$shortcuts = gci "$srcDir\*.lnk"

cgi = Get-ChildItem  Microsoft

Gets the items and child items in one or more specified locations.

# skip existing dirs

if (Test-Path "$destPath") {

Test-Path Microsoft

Determines whether all elements of a path exist.

# copy

copy-item -Path "$srcPath" -Destination "$destRecreatePath" -Force -Recurse -Container -Exclude $exclude

copy-item Microsoft

Copies an item from one location to another.

But alas, without any indication of progress.

So, from some help on Stack Overflow

# xcopy prompts for is this a file/dir, no progress

# robocopy asks for admin perms on ntfs/audit attribs

# copy copies with progress %

# /z   : Copies networked files in restartable mode.

cmd /c copy /z $srcFile $destFile


Some screenshots of the full script in action












And the full source is on GitHub

End of document. Thanks for reading.

A proper wrapper for console.log with correct line number?

Details
Published: 02 July 2018
  • javascript

While writing a simple JavaScript 'class', I wanted to toggle console.logs on for development and off for production.  Normally I would create a method to wrap console.log with a debug flag, such as:

function Awesome() {
   this.debug = true;

   this.log = function(msg) {
       if (this.debug) {
           console.log(msg);    // line 6
       }
   };   

   this.log('test');            // outputs line 6

   this.doStuff = function() {
       this.log('doing stuff'); // outputs line 6
   };
}

But the line number logged is always from within the log wrapper, this.log(),
which is not overly useful.
After some searching, I ran across this StackOverflow thread
https://stackoverflow.com/a/13815846/3893727
Basically, instead of using a logging wrapper, use a function alias.

function Awesome() {

   this.debug = true;   

   if (this.debug && window.console && console.log && console.warn && console.error) {

       this.console = {
           'log': window.console.log,
           'warn': window.console.warn,
           'error': window.console.error
       };

   } else {

       this.console = {
           'log': function(){},
           'warn': function(){},
           'error': function(){}
       };
   }

   this.console.log('test');            // outputs line 18

   this.doStuff = function() {
       this.console.log('doing stuff'); // outputs line 21
   };
}    

So now Awesome is awesome with logging showing the original line number,
which is helpful for debugging.

Of course, this.console could be renamed to anything, such as this.log, this.out, etc.
And you could add the log to the window namespace so it could be used by other functions, such as window.debug or window.log, etc

End of document. Thanks for reading.

Portable DBeaver

Details
Published: 25 June 2018
  • portable
  • dbeaver
DBeaver is a most excellent Universal SQL Client
https://dbeaver.jkiss.org

“Free multi-platform database tool for developers, SQL programmers, database administrators and analysts. Supports all popular databases: MySQL, PostgreSQL, MariaDB, SQLite, Oracle, DB2, SQL Server, Sybase, MS Access, Teradata, Firebird, Derby, etc.”

You can also buy and support DBeaver, or if you need more features, at
https://dbeaver.com

“Best multi-platform database tool for developers, database administrators and analysts. Supports all popular relational databases: MySQL, PostgreSQL, SQLite, Oracle, DB2, SQL Server, MariaDB, Sybase, Teradata, Netezza, etc. Supports NoSQL databases: MongoDB, Cassandra, Redis, Apache Hive, etc.”

Note: If you can, install the latest executable DBeaver, which will give you the option to keep the program auto updated.

But if due to your company’s security policies, you are not be able to update to the latest required DBeaver or even install the DBeaver executable (exe), you can often download and use the portable versions of programs, often distributed as zip, tar, or gz files.

Or maybe you just want a portable and easy to backup version of the DBeaver.

Download the latest version of DBeaver
DBeaver 
https://dbeaver.jkiss.org/download/

Be sure to download the appropriate OS version and the zip file




Extract either download to a directory, such as 
C:\Portable\DBeaver

Note: BandiZip is a good free archive (zip) program


To run DBeaver, you must have a Java JRE installed or a portable copy.
Note: This Blog post will show you how to create a portable copy of the Java JRE
Portable Java


If using a portable version of the Java JRE, 
Edit the DBeaver configuration file to tell DBeaver where your portable version of Java JRE is located.

Open the file
C:\Portable\DBeaver\dbeaver.ini




Note: Notepad++ is a good free text editor, which can also be used portable
just download the zip or 7z version.

Add -vm and path to jvm lines in between the -showsplash and -vmargs lines
Make sure -vm is on one line, and the path to jvm.dll on the next line

..
-showsplash
-vm 
C:\Portable\jre-10.0.1\bin\client\jvm.dll
-vmargs
..

Create a shortcut to the DBeaver executable, which is in 
C:\Portable\DBeaver\



Add to the shortcut the parameter 
-data .dbeaver


This will create the DBeaver configuration in the same directory as the dbeaver.exe
C:\Portable\DBeaver\.dbeaver

Else, the DBeaver configuration will be created in your users home directory

Save and close and try to run DBeaver 

DBeaver should be up and running.

Query away!




Additional Information

Your company policies may prevent the auto downloads of required Java database drivers, which are often distributed as jar files (compressed java files)

Try to create a new database connection
Right click on the Database Navigation pane
Choose Create New Connection




Choose a database to connect to, 
in this example PostgreSQL (Postgres) was chosen

Click either Driver properties or Edit Driver Settings

If you are missing drivers or DBeaver cannot auto download them, DBeaver will notify you and the drivers will be in red



You can try setting the download proxy, if you have that information




If not, you can try to download the drivers directly.

For Postrgres, download the driver jar files from
https://jdbc.postgresql.org/download.html (42.2.2)
https://mvnrepository.com/artifact/net.postgis/postgis-jdbc-jtsparser/2.2.1 (2.2.1)
https://mvnrepository.com/artifact/net.postgis/postgis-jdbc/2.2.1 (2.2.1)

Note: These urls were found by searching for the driver name and version listed by DBeaver

Then click Add File for each jar file.
And also remove the prior entries.




That should get you Querying

End of document. Thanks for reading.
  1. Portable Netbeans
  2. Portable Java

Page 15 of 21

  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

Search

Tags

php 21 git 10 windows 10 aws 9 nodejs 7 security 6 virtualbox 6 android 5 portable 4 redhat 4 ubuntu 4 react native 3 reactjs 3 docker 3 devops 3 nginx 3 bash 3 symfony 3 apache 3 ide 2

Most Read Posts

  • Handle HTTP 302 response from proxy in Angular
  • PHPUnit exceeds memory limit
  • Adding camera api to react native
  • Portable Java
  • Clear out old MSMQ messages

Older Posts

  • HDMI and Display Port versions
  • Useful Linux Commands
  • DevOps SysAdmin Tips for researching a slow or unresponsive app or system
  • DDEV for local development in containers
  • Valid local self signed certs
  • Bash script to delete merged local git branches
My Blog