Wednesday 15 July 2020

Export and Import all MySQL databases at one time

https://stackoverflow.com/questions/9497869/export-and-import-all-mysql-databases-at-one-time

Export and Import all MySQL databases at one time

mysqldump -u root -p --all-databases > alldb.sql
Look up the documentation for mysqldump. You may want to use some of the options mentioned in comments:
mysqldump -u root -p --opt --all-databases > alldb.sql
mysqldump -u root -p --all-databases --skip-lock-tables > alldb.sql

Import:

mysql -u root -p < alldb.sql

Get size of all tables in database


https://stackoverflow.com/questions/7892334/get-size-of-all-tables-in-database

Get size of all tables in database

SELECT 
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
    CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    TotalSpaceMB DESC, t.Name

Tuesday 7 July 2020

How to run SQL script in MySQL?

 

How to run SQL script in MySQL?

 
 
mysql --user="username" --database="databasename" --password="yourpassword" < "filepath"

Lists, Arrays, and Hashtables

https://www.oreilly.com/library/view/windows-powershell-cookbook/9781449359195/ch07.html

Lists, Arrays, and Hashtables

Introduction

Most scripts deal with more than one thing—lists of servers, lists of files, lookup codes, and more. To enable this, PowerShell supports many features to help you through both its language features and utility cmdlets.
PowerShell makes working with arrays and lists much like working with other data types: you can easily create an array or list and then add or remove elements from it. You can just as easily sort it, search it, or combine it with another array. When you want to store a mapping between one piece of data and another, a hashtable fulfills that need perfectly.

Create an Array or List of Items

Problem

You want to create an array or list of items.

Solution

To create an array that holds a given set of items, separate those items with commas:
PS > $myArray = 1,2,"Hello World"
PS > $myArray
1
2
Hello World
To create an array of a specific size, use the New-Object cmdlet:
PS > $myArray = New-Object string[] 10
PS > $myArray[5] = "Hello"
PS > $myArray[5]
Hello
To create an array of a specific type, use a strongly typed collection:
PS > $list = New-Object Collections.Generic.List[Int]
PS > $list.Add(10)
PS > $list.Add("Hello")
Cannot convert argument "0", with value: "Hello", for "Add" to type "System
.Int32": "Cannot convert value "Hello" to type "System.Int32". Error:
"Input string was not in a correct format.""
To store the output of a command that generates a list, use variable assignment:
PS > $myArray = Get-Process PS > $myArray Handles ...

Wednesday 1 July 2020

Delete files or folder recursively on Windows CMD

https://stackoverflow.com/questions/12748786/delete-files-or-folder-recursively-on-windows-cmd

Delete files or folder recursively on Windows CMD

 

You can use this in the bat script:
rd /s /q "c:\folder a"
Now, just change c:\folder a to your folder's location. Quotation is only needed when your folder name contains spaces.
 
 
The other answers didn't work for me, but this did:
del /s /q *.svn
rmdir /s /q *.svn
/q disables Yes/No prompting
/s means delete the file(s) from all subdirectories.
 

 

Which file does robocopy copy first?

https://superuser.com/questions/378200/which-file-does-robocopy-copy-first

Which file does robocopy copy first?

 

If you want to copy newer (recent) files first, you could use the Robocopy /MAXAGE:n and /MINAGE:n command line options.
You will have to run Robocopy 2 or more times (depending on how much you want to control the file copy order by the "age" of the files).
Here is information about the /MAXAGE:n and /MINAGE:n command line options:
/MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.
/MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.
    (If n < 1900 then n = n days, else n = YYYYMMDD date).
In the simplest case for example, you could first copy files that are AT-MOST 1 day old, then when that is finished, copy all files that are AT-LEAST 1 day old. Here are the 2 Robocopy command lines for this (first) example:
First run of Robocopy:
    robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:1
Second run of Robocopy:
    robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MINAGE:1
If you want more control than that, you can combine the 2 options. For example:
  1. First copy all files that are AT-MOST, 1 day old
  2. Then copy files that are AT-LEAST 1 day old, and AT-MOST 2 days old
  3. Then copy files that are AT-LEAST 2 days old, and AT-MOST 3 days old
  4. Then copy files that are AT-LEAST 3 days old, and AT-MOST 5 days old
  5. Then copy files that are AT-LEAST 5 days old (all remaining filea)
Here are the Robocopy command lines for this (second) example:
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:1
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:2 /MINAGE:1
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:3 /MINAGE:2
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:5 /MINAGE:3
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MINAGE:5

If you want to see the order that Robocopy will use to copy the files, you could use the /L option:
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:1 /L
With the /L option, Robocopy will just list the files that "would" be copied, but will not actually copy any files.