Monday, August 23, 2021

Backups with a bat file in windows

I was thinking about how to backup from one computer to another on the same network. Well that seems simple, however things are never as simple as they seem when it comes to computing.

My requirements are:

    The task must be executed from the server where the information will be saved. That means that the task must be executed without a user being logged in and also with the administrator permissions to enter the source computer.

The first thing that occurred to me was that I could use the windows task scheduler on the server to run a script that would connect to the source computer and then copy over the network to the destination computer, which is the same at that time. server from where the task runs.

Well, doing a bit of research on the internet I found the xcopy command, which can be used with a BAT file extension. Example:

Xcopy "\\computer-name\01_documents" "d:\2021\BackupDocuments" /c /d /e /s /i /y

You can see the reference here: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy

One of the options with the diagonals allows it to be incremental. These options can be seen in the reference.

Well that works, as long as the user executing the command has permissions to enter the source computer. In my case I need the command to be executed when no one is logged into the server.

Well, continuing with my research I found the command "net use". This command allows you to connect to a shared network resource from another computer. Example:

net use M: \\computer-name\01_documents passwordAdmin /user:computer-name\admin

In this case create a connection as drive "M" to share "\\computer-name\01_documents" with user "admin" with password "passwordAdmin"

Now I can enter drive M as if it were another drive on my computer. That means you could use the command:

 Xcopy M: "d:\2021\BackupDocuments" /c /d /e /s /i /y

Now all I have to do is delete that connection so that it does not remain on the server, that is done with the command:

net use M:/delete

In the end then the BAT file would be:

net use M:\\computer-name\01_documents passwordAdmin /user:computer-name\admin
Xcopy M: "d:\2021\BackupDocuments" /c /d /e /s /i /y
net use M:/delete

Now the only thing I need is to schedule the task in the windows 2021 R2 task scheduler to run when there is no user logged on to the computer.

 

Versión en Español:

Estaba pensando en cómo hacer backups de una computadora a otra en la misma red. Bueno eso parece sencillo, sin embargo las cosas nunca son tan sencillas como parecen cuando se trata de informática.

Mis requerimientos son:  

  1. La tarea se debe ejecutar desde el servidor en dónde se estará guardando la información. Eso quiere decir que la tarea se debe ejecutar sin que un usuario esté logueado y además con los permisos de administrador para entrar a la computadora origen.

Lo primero que se me ocurrió fue que podría usar el programador de tareas de windows en el servidor para ejecutar un script que se conectara a la computadora origen y luego copiara a través de la red hacia la computadora destino, que en este caso es el mismo servidor desde donde se ejecuta la tarea. 

Bien, haciendo un poco de investigación en internet encontré el comando xcopy, que se puede usar con un archivo de extensión BAT.  Ejemplo:

Xcopy "\\computer-name\01_documents" "d:\2021\BackupDocuments" /c  /d  /e  /s  /i  /y

Pueden ver la referencia aquí: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy

Una de las opciones con las diagonales permite que sea incremental. Estas opciones las pueden ver en la referencia.

Bueno eso funciona, siempre y cuando el usuario que ejecute el comando tenga permisos para entrar a la computadora origen. En mi caso necesito que el comando se ejecute cuando nadie esté logueado al servidor.

Bien, siguiendo con mi investigación encontré el comando "net use". Este comando permite conectarse a un recurso de red compartido desde otra computadora. Ejemplo:

net use M: \\computer-name\01_documents passwordAdmin /user:computer-name\admin 

En este caso crea una conexión como unidad "M" al recurso compartido  "\\computer-name\01_documents" con el usuario "admin" con password "passwordAdmin"

Ahora ya puedo entrar a la unidad M como si fuera una unidad más en mi computadora. Eso quiere decir que podría usar el comando:

 Xcopy M: "d:\2021\BackupDocuments" /c  /d  /e  /s  /i  /y

Ahora lo único que tengo que hacer es eliminar esa conexión para que no quede en el servidor, eso se hace con el comando:

net use M: /delete

Al final entonces el archivo BAT quedaría:

net use M: \\computer-name\01_documents passwordAdmin /user:computer-name\admin 
Xcopy M: "d:\2021\BackupDocuments" /c  /d  /e  /s  /i  /y
net use M: /delete

Ahora lo único que me falta es programar la tarea en el programador de tareas de windows 2021 R2 para que se ejecute cuando no exista ningún usuario logueado a la computadora.

 

Thursday, August 19, 2021

Task manager does not show most of the process

 Well, i was doing some coding in vb.net and a line was like this:

SetLocaleInfo(LOCALE_USER_DEFAULT, &HE, ".")

to set a new decimal separator. (don't ask why)

But there was an exception when i was trying the code.  

In the end the problem ocurred when it let the decimal separator in blank.  You would think that does not care, but it does to me.  

My ArcGis software stop working. It was showing an error message syaing the default database .gdb was corrupted.  Also the task manager in windows 10 does not show most of the process.  

It took me a while to find the error, but in the end I resolve it just by stablishing the dot as a decimal separator in